finite state machine, need explaining

Discussion in 'General Electronics Chat' started by bug13, Feb 1, 2015.

  1. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    Hi guys

    I come across this term from time to time. I believe I understand it, but also I am not quite sure what it is exactly.

    Can you give me some simple example/applications with explanation in simple English to help me understand it better?

    thanks a lot.
     
  2. WBahn

    Moderator

    Mar 31, 2012
    17,747
    4,796
    FSM - Finite State Machine

    Is basically a machine that has a finite number of states. (Duh!)

    At any given time it is in exactly one state.

    The present inputs determine whether or not it moves to a different state and, if so, which one.

    So imagine you have two push buttons that each produces one pulse each time it is pressed. You have two lights, Red and Green, and you want the following behavior:

    Exactly one light is always on.
    Pressing Button A three times in a row (since this light went on) will toggle the lights.
    Pressing Button B twice in a row (since this light went on) will toggle the lights.

    Because I am always in one state and that is all the information I know, the fact of which state I am in has to capture all of the relevant information. So for this system I would probably need the following states:

    1) Green light just came on
    2) Green light on and Button A pressed once
    3) Green light on and Button A pressed twice
    4) Green light on and Button B pressed once
    5) Red light just came on
    6) Red light on and Button A pressed once
    7) Red light on and Button A pressed twice
    8) Red light on and Button B pressed once

    Now I just need to consider what I should do from each state depending on which button gets pressed:

    (1) -- A --> (2)
    (2) -- A --> (3)
    (3) -- A --> (5)
    (4) -- A --> (2)
    (5) -- A --> (6)
    (6) -- A --> (7)
    (7) -- A --> (1)
    (8) -- A --> (6)

    Can you figure out the comparable table for button B being pressed?
     
    absf and bug13 like this.
  3. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    Aha, I think I got it.

    Assuming when you say toggle the lights, you mean (GREEN ON, RED OFF) -> (GREEN OFF, RED ON) or vise versa. So (in my word) that's how I understand it:

    - figure all unique possible state
    - at any time, there is only one state
    - what is the next state (or no change) with current input

    So the comparable table for button B being pressed is:

    (1) -- B --> (4)
    (2) -- B --> (4)
    (3) -- B --> (4)
    (4) -- B --> (5)
    (5) -- B --> (8)
    (6) -- B --> (8)
    (7) -- B --> (8)
    (8) -- B --> (1)

    Is that correct?
     
  4. WBahn

    Moderator

    Mar 31, 2012
    17,747
    4,796
    Yep. I think you've got it.
     
  5. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    Thanks for you help aagain, WBahn!! appreciate it!!
     
Loading...