Finite State Machine – Designing FSM for x/3

state-machines

I was asked to design a FSM for outputting x/3 without the remainder.

This should be implemented using a synchronous system defined as follows:

input: on each clock cycle t, one bit x[t]

output: on each clock cycle t, one bit y[t]

functionality:

let x be a number represented by concatenation of the input bits where x[t] is the LSB

let y be a number represented by concatenation of the output bits where y[t] is the LSB

so y is the result of x/3 (the floor function with x/3 as argument)

e.g.:

t 1 2 3 4

x[t] 1 0 1 0

y[t] 0 0 1 1

I am including two attempts, yet neither is actually yielding the correct result but rather the remainder (i.e. x mod 3), right? They were both intended to yield x/3 and yet it seems they both yield the remainder instead.

enter image description here
enter image description here

Best Answer

I think you already did pretty much the right thing. The table looks like this:

$$\begin{array}{r|cc} & \textrm{bits:}\\ & 0 & \quad1\\ \hline \textrm{states:}\quad0 & 0:`0\textrm' & \quad1:`0\textrm'\\ 1 & 2:`0\textrm' & \quad 0:`1\textrm'\\ 2 & 1:`1\textrm' & \quad 2:`1\textrm' \end{array}$$

You enter (start) at state 0 and then index into the table as bits arrive. So the state diagram looks like:

enter image description here

I've added the "emit" parts, as this is what is needed for you to get the quotient. (Obviously, the remainder is the state itself.) You will need some method of accumulating bits that are emitted (shift register, for example.)

Here are the results for all four-bit input values:

$$\begin{array}{r|cc} \textrm{input} & \textrm{emitted output} & \textrm{remainder (state)}\\ \hline 0000 & 0000 & 0\\ 0001 & 0000 & 1\\ 0010 & 0000 & 2\\ 0011 & 0001 & 0\\ 0100 & 0001 & 1\\ 0101 & 0001 & 2\\ 0110 & 0010 & 0\\ 0111 & 0010 & 1\\ 1000 & 0010 & 2\\ 1001 & 0011 & 0\\ 1010 & 0011 & 1\\ 1011 & 0011 & 2\\ 1100 & 0100 & 0\\ 1101 & 0100 & 1\\ 1110 & 0100 & 2\\ 1111 & 0101 & 0 \end{array}$$

Related Topic