Professional Documents
Culture Documents
Lumayaga
Homework 3
Consider the design of a Moore-style FSM with a 1-bit input (x), and a 1-bit output (y). The FSM accepts
inputs one bit at a time and outputs a 0 until it sees the sequence 0101 (with no other bit values in
between). After seeing the second 1 in the sequence it outputs a 1 and then starts over.
(a) Draw the state transition diagram. Label all nodes and arcs.
(b) Derive the next state logic and the output logic equations.
SOLUTION:
(a):
(b): One way is to use one-hot encoding and 5 bits to express states:
You can then use Karnaugh-maps to derive simplified expressions for each bit of
the next state n from the current state c and input x.
Problem 2: Implementing an FSM
(a) Write the Verilog behavior description for the corresponding circuit.
(b) Draw the circuit diagram for one-hot encoded implementation. (You may assume that flip-flops have
both "set" and "reset" inputs, but you must label which one you would use for each flip-flop.)
SOLUTION:
(a)
(b):
Problem 3: Converting from Mealy to Moore Style
SOLUTION:
The State Diagram of the Vending Machine is given here. It has the following states:
State 1: Reset
State 2: Five
State 3: Ten
State 4: Fifteen
State 5: Twenty
The next state is the RESET state again. The diagram is given below and is self-explanatory. Whenever a
coin is dropped, the system jumps to the next state. For example, if the coin dropped from the RESET
State is a NICKEL, then the system jumps to the FIVE State. Otherwise, the system stays in the present
state. When the system gets an extra amount, it goes back to the RESET State and the difference is given
back to the user. Write the Verilog behavior description of this vending machine system.
SOLUTION:
\\module name
module fsm(clock,reset,coin,vend,state,change);
output vend;
output [2:0]state;
output [2:0]change;
parameter [2:0]IDLE=3’b000;
parameter [2:0]FIVE=3’b001;
parameter [2:0]TEN=3’b010;
parameter [2:0]FIFTEEN=3’b011;
parameter [2:0]TWENTY=3’b100;
parameter [2:0]TWENTYFIVE=3’b101;
default : next_state=IDLE;
endcase
end
always @(clock)
begin \\if reset, state=idle and vend=1
if(reset) begin
state <= IDLE;
vend <= 1’b0;
// change <= 3’b000;
end \\ change must be none
else state <= next_state;
case (state) \\ case for next state
\\the states are defined and output is given
end
endmodule