# Design Finite State Machine

I need to design a finite state machine that detects any invalid button sequences for a set of instructions. The scenario is a factory where the person must press POWER, WELD, and than POWER and that is the only valid set of button sequences for the machine to work properly. The instructions that I have state the user must press POWER to begin the machine, than WELD to weld the part, and finally POWER again to to turn off the machine. So for example a button sequence o POWER, POWER, WELD will result in an error. When designing the finite state machine for this scenario to capture only failures I tried to list all of the possibilities of a fail:

P P W

P P P

W W W

W P P

P W W

W W P

W P W

I think I am missing one, but I am not sure? Now when actually designing it I have four state bubbles, with the outputs FAIL=0, FAIL=0, FAIL=0, and FAIL=1 for the last bubble. How can I go about implementing all of these cases without drawing so many lines from bubble to bubble and having a mess? Thank you!

• What do you want to happen if the user pushes POWER POWER WELD POWER? Jul 24, 2013 at 16:52
• That's an error I believe. The instructions that I have state the user must press POWER to begin the machine, than WELD to weld the part, and finally POWER again to to turn off the machine. So I am assuming pressing POWER twice initially will cause an error and turn off the machine. Sorry for not stating that in my original post. Jul 24, 2013 at 16:56
• Is this a learning excercise / homework or are you designing a real machine? Jul 24, 2013 at 17:46
• It's a learning exercise/homework. Jul 24, 2013 at 18:36

Based on comments (the drawing tool didn't separate out the R and W; W goes to 4, and R goes to S):

• Thank you! What do the asterisks * represent in the above model? And I am assuming S is start? So I need 6 state bubbles how many will have an output of F=0 or F=1 for a failure? Jul 24, 2013 at 17:39
• The * represents any input. States 4, 5, and 6 are all failure states. Jul 24, 2013 at 17:41
• Some of these states are redundant, no? S->P->P ends up at 6. S->W ends up at 6, etc Jul 24, 2013 at 17:41
• @dext0rb: Only if not all three presses are required. I inferred from the question that e.g. P -> P -> P would be failure all throughout and not return to the initial state after the second P. Jul 24, 2013 at 17:45
• @CharlesWitiker: If that's how you're representing the input, sure. Jul 24, 2013 at 17:47

Please see this state transition table (notation explained in http://en.wikipedia.org/wiki/State_transition_table#Two-dimensional_state_tables)

            |    POWER          WELD
| -----------------------
->INITIAL |        P          FAIL
P |     FAIL            PW
PW |      PWP          FAIL
PWP |     FAIL          FAIL
FAIL |     FAIL          FAIL


State INITIAL is starting state. State PWP is accepting state - if you end up in this state after reading whole input sequence (must be exactly 3 button presses in defined order (power, weld, power)), you are accepting the sequence.

Otherwise if anything unwanted occurs (wrong button, incorrect number of button presses), state machine transitions to the FAIL state, where it stays until forever. If you end up in this state after reading whole input, you know that the user pressed incorrect buttons in incorrect order or whatever.