1 FSMDesignWithVerilog
1 FSMDesignWithVerilog
STATE MACHINES
(Sequential + Combinational )
❖ The values stored in these devices are called the state of the
circuit.
Inputs Next
Next State Output
State Present State
State Memory Logic
Logic
Clock Input
Next Outputs
Inputs Next State Output
State Present State
State Memory Logic
Logic
Clock Input
Rising Rising
edge of edge of
Rising
Clk Clk
edge of
Clk
// --------------------------------------------
//
// S T A T E M A C H I N E DESIGN OF A 2 BIT COUNTER
//
// --------------------------------------------
module state_machine(clk,reset,d_out);
input clk;
input reset;
output [1:0] d_out;
reg [1:0] current_state, next_state;
always @ (current_state)
begin
case (current_state)
CNT0:
next_state = CNT1; //
d_out = 1'b0; // What kind of a machine is this: Mealy or moore?
CNT1:
next_state = CNT2;
d_out = 2'b01;
CNT2:
next_state = CNT3;
d_out = 2'b10;
CNT3:
next_state = CNT0;
d_out = 2'b11;
end
endmodule
// --------------------------------------------
//
// Questions:
//
// --------------------------------------------
2) Next state logic affected by this mode input. Need to check this
value before deciding next state
3) Draw the next state logic on paper and verify with the
Synthesized design
State Machine Design
Example: A Traffic Light Controller
TIMER2 TIMER3
RESET
(asynchronous)
TIMER1 TIMER2
RED GREEN YELLOW
R='1' Y='1'
TIMER1 G='1'
TIMER3
One Hot Encoding
• Decoding the state = extremely simple (just finding out which bit =
‘1’)
• Changing states = simply changing new flip flop to ‘1’ and old one to
‘0’;
• Advantages :
– Logic gates required for decoding state information and
changing state is minimal.
Disadvantages:
- Uses more flip flops/ registers.
http://www.eetimes.com/document.asp?doc_id=1206481