Beruflich Dokumente
Kultur Dokumente
distinct states
! Counters are simple FSMs " Outputs and states are identical " Visit states in a fixed sequence ! FSMs are more complex than counting " Outputs can depend on current state and on inputs " State sequencing depends on current state and on inputs
CSE370, Lecture 21
CSE370, Lecture 21
reg
state feedback inputs logic for outputs combinational logic for next state state feedback
CSE370, Lecture 21
outputs reg
Inputs
Mealy machine Outputs depend on state and on inputs Input changes can cause immediate output changes (asynchronous)
4
DQ Q DQ Q
DQ Q DQ Q
current output 0 0 0 0 0 0 0 1 1 1 1
6
reset
A/0 1 C/0 1 1 0
D Q Q D Q Q
5
E/1
CSE370, Lecture 21
current output 0 0 0 0 1 1 0
0/1
1/1
CSE370, Lecture 21
FSM design
! Generalized counter design
"
Counter-design procedure
1. 2. 3. 4. State diagram State-transition table Next-state logic minimization Implement the design
inputs
logic for outputs combinational logic for next state state feedback
reg reg
outputs
"
FSM-design procedure
1. 2. 3. 4. 5. State diagram and state-transition table State minimization State assignment (or state encoding) Next-state logic minimization Implement the design
CSE370, Lecture 21
CSE370, Lecture 21
10
Input 0 1 0 1
CSE370, Lecture 21
Implementation
! Can map FSMs to programmable logic devices " Macro-cell = DFF + two-level logic
Assume D flip-flops Next state = (present state) XOR (present input) Present output = present state
Input
Q Q
Output
CLK
CSE370, Lecture 21
13
Combinational circuit
Flip-flops
Combinational circuit
Clockcycle: w: z:
t0 0 0
t1 1 0
t2 0 0
t3 1 0
t4 1 0
t5 0 1
t6 1 0
t7 1 0
t8 1 1
t9 0 1
t10 1 0
Clock
CSE370, Lecture 21
15
CSE370, Lecture 21
16
Reset w = 1 w = 0 Az = 0 w = 0 w = 0 w = 1 Bz= 0
Present state A B C
Next state
w= 0
A A A
w= 1
B C C
Output z 0 0 1
Cz = 1
w = 1
CSE370, Lecture 21
17
CSE370, Lecture 21
18
w Combinational circuit
Y1
y1 Combinational circuit
Present
z
state y y 2 1 A B C 00 01 10 11
Y2
y2
Clock
CSE370, Lecture 21
19
CSE370, Lecture 21
20
Y2 D
y y 2 1 w 0 1 00 0 0 01 0 1 11 d d 10 0 Y 1 2 = wy y + wy y 1 2 1 2 Y 2 = wy + wy 1 2 = w(y + y ) 1 2
y2 Q Q
Y1 w
y y 2 0 1 1 0 0 1 1 0 z = y y 1 2 d z = y 2
y1 D Q Q
Clock Resetn
CSE370, Lecture 21
21
CSE370, Lecture 21
22
module simple (Clock, Resetn, w, z); input Clock, Resetn, w; output z; reg [2:1] y, Y; parameter [2:1] A = 2'b00, B = 2'b01, C = 2'b10; // Define the next state combinational circuit always @(w or y) case (y) A: if (w) Y = B; else Y = A; B: if (w) Y = C; else Y = A; C: if (w) Y = C; else Y = A; default: Y = 2'bxx; endcase // Define the sequential block always @(negedge Resetn or posedge Clock) if (Resetn == 0)y <= A; else y <= Y; // Define output assign z = (y == C); endmodule CSE370, Lecture 21
module simple (Clock, Resetn, w, z); input Clock, Resetn, w; output z; reg [2:1] state, NextState; parameter [2:1] stateA = 2'b00, stateB = 2'b01, stateC = 2'b10; // Define the next state combinational circuit always @(w or state) case (state) stateA : if (w) NextState = stateB; else NextState = stateA; stateB : if (w) NextState = stateC; else NextState = stateA; stateC : if (w) NextState = stateC; else NextState = stateA; default: NextState = 2'bxx; endcase // Define the sequential block always @(negedge Resetn or posedge Clock) if (Resetn == 0) state <= stateA; else state <= NextState; // Define output assign z = (state == stateC); endmodule
23
CSE370, Lecture 21
Figure 8.29. Re-written Verilog code for the FSM in Figure 8.3. 24