Skip to main content Link Menu Expand (external link) Document Search Copy Copied
Table of contents
  1. Frame State Machine
    1. States
    2. Handlers
  2. FSM Diagram
  3. Implementation on the Microcontroller

Frame State Machine

The frame analysis goes through a finite state machine, processing each bit of this frame.

States

  • IDLE : Waiting for a frame (default state).
  • START : Frame start bit correct.
  • DATA : Comprised of two parts, command and params.
  • PARITY : Frame parity correct.
  • STOP : Frame stop bit correct.

Each state has its own handler.

Handlers

  • IdleHandler : gets called when a frame starts being received by the analyzing timer, then goes to START state.
  • StartHandler : checks if start bit is correct, and starts the translation of the rest of the frame. Goes to DATA state if successful.
  • DataHandler : gets the command and parameters from the frame by getting each data bit and storing it, then goes to PARITY state.
  • ParityHandler : checks the parity of the previous processed bits against its parity bit. Goes to STOP state if successful.
  • StopHandler : checks if stop bit is correct. Goes back to IDLE state.

If any of the handlers fails, resets back to IDLE state.

When the StopHandler succeeds, the FSM sends the validated data as a movement order to the Motors.

FSM Diagram

frameFSM

Implementation on the Microcontroller

The code is available in frameFSM.c.


Back to top

Copyright © 2023 Martin Fonteyn, Lucas Placentino and Sylvain Powis de Tenbossche - EPB ULB