# State machine design

#### tux

Joined Nov 11, 2012
8

#### Papabravo

Joined Feb 24, 2006
17,228
Your Gray code sequence is wrong. I know this because only one bit can be different between successive values of the counter. The sequence should be {001, 011, 010, 110, 111, 101, 100, 000} or {1, 3, 2, 6, 7, 5, 4, 0}

#### tux

Joined Nov 11, 2012
8
According to wikipedia the sequence is {0,1,3,2,6,7,5,4}.
Since this is an up/down counter then my state table should look like this:

Present state | Input (x) | Next state | Output(A) |

000 0 001 0
000 1 001 0 <------- From state 0 to state 1 (Gray code)
001 0 010 0
001 1 011 0 <------- From state 1 to state 3 (Gray code)
010 0 011 0
011 1 010 0 <-------- From state 3 to state 2 (Gray code)
.
.
.
Should I separate cases for normal counting and gray code counting?

#### Papabravo

Joined Feb 24, 2006
17,228
According to wikipedia the sequence is {0,1,3,2,6,7,5,4}.
Since this is an up/down counter then my state table should look like this:

Present state | Input (x) | Next state | Output(A) |

000 0 001 0
000 1 001 0 <------- From state 0 to state 1 (Gray code)
001 0 010 0
001 1 011 0 <------- From state 1 to state 3 (Gray code)
010 0 011 0
011 1 010 0 <-------- From state 3 to state 2 (Gray code)
.
.
.
Should I separate cases for normal counting and gray code counting?
Any cyclic permutation of a state sequence is equivalent to any other. So I have no quibble with Wikipedia. You should be able to switch from normal to Gray code or vice versa on any clock transition.

tux