Professional Documents
Culture Documents
Finite State Machine (FSM)
Finite State Machine (FSM)
Shared RAM
A B C
Start Done
Controller
WAIT_B
9. Return to State 1 9. Return to State 1
done_b
Sequence of Steps
Mealy’s Machine
WAIT_C State Registered
done_c|done
outputs
Outputs are dependant
on state and input
So we need to mention
inputs and outputs on
state transitions
1
1/22/2014
always@(*)
begin
Combinational
start|
Feed back (AKA start_a=1
parameter IDLE = 2’d0; Latch)… Never
parameter WAIT_A = 2’d1; case(state) allow it… IDLE
IDLE:
parameter WAIT_B = 2’d2; if(start)
parameter WAIT_C = 2’d3; Inputs Outputs begin
State start_a = 1; done_a|
state_nxt = WAIT_A; WAIT_A start_b=1
reg [1:0] state; end
reg [1:0] state_nxt; State
WAIT_B
start
inputs Outputs done_b|
always@(posedge clk) start_c=1
begin 1
if(reset) IDLE start_a
WAIT_C done_c|
state <= #1 IDLE; WAIT_A
done=1
WAIT_B
else WAIT_C
state <= #1 state_nxt;
end
endcase
end
always@(*) always@(*)
begin begin
!start|
start_a = 0; start_a = 0;
start_a=0
start_b = 0; start_b = 0;
start_c = 0; start| start_c = 0; start|
done = 0; start_a=1 done = 0; start_a=1
state_nxt = state; start_b=0 state_nxt = state;
case(state) start_c=0 case(state)
IDLE IDLE
done=0
IDLE: IDLE:
if(start) if(start)
begin begin
start_a = 1; done_a| start_a = 1; done_a|
state_nxt = WAIT_A; WAIT_A start_b=1 state_nxt = WAIT_A; WAIT_A start_b=1
end end
State !done_a| WAIT_A:
start_b=0 if(done_a)
begin
WAIT_B start_b = 1; WAIT_B
start state_nxt = WAIT_B;
done_b| end done_b|
start_c=1 !done_b| WAIT_B: start_c=1
1 start_c=0 if(done_b)
begin
0 IDLE start_a done_c| start_c = 1; done_c|
0 WAIT_A WAIT_C
done=1 state_nxt = WAIT_C; WAIT_C
done=1
0 WAIT_B end
0 WAIT_C WAIT_C:
if(done_c)
!done_c| begin
done=0 done = 1;
state_nxt = IDLE;
end
endcase endcase
end end
state
One-Hot generally
FAST but consumes start
MORE FLIPFLOPS.
1
0 IDLE start_a
0 WAIT_A
0 WAIT_B
0 WAIT_C
2
1/22/2014
state state
One-Hot generally One-Hot generally
FAST but consumes start FAST but consumes start
MORE FLIPFLOPS. MORE FLIPFLOPS.
1 1
What if it had been What if it had been
a Moore’s Machine? 0 IDLE start_a a Moore’s Machine? 0 IDLE start_a
0 WAIT_A 0 WAIT_A
But remember it had 0 WAIT_B But remember it had 0 WAIT_B
eight states… 0 WAIT_C eight states… 0 WAIT_C
So generally a ONE-HOT Moore
machine is FASTER at the cost of
more FLIPFLOPS