Professional Documents
Culture Documents
06 SeqLogicII
06 SeqLogicII
Design procedure
State diagrams State transition table Next state functions
Combinational Logic
State Outputs
Clock
CS 150 - Spring 2007 Lec #6: Moore and Mealy Machines - 3
Sequential Logic
Sequences through a series of states Based on sequence of values on input signals Clock period defines elements of sequence
ERR closed not equal & new reset S1 closed mux=C1 equal & new not new S2 closed mux=C2 equal & new not new not equal & new not equal & new OPEN open
1 1 101 1 1
000
3-bit up-counter
100
111
110
101
Verilog Upcounter
module binary_cntr inputs clk; outputs [2:0] reg [2:0] reg [2:0] (q, clk) q; q; p;
always @(q) //Calculate next state case (q) 3b000: p = 3b001; 3b001: p = 3b010; 3b111: p = 3b000; endcase always @(posedge clk) q <= p; endmodule
CS 150 - Spring 2007 Lec #6: Moore and Mealy Machines - 8
Wait long enough for combinational logic to compute new value Don't wait too long as that is low performance
OUT1 D Q CLK D Q OUT2 D Q OUT3
"1"
CS 150 - Spring 2007 Lec #6: Moore and Mealy Machines - 9
State encoding
Decide on representation of states For counters it is simple: just its value Flip-flop for each state bit Combinational logic based on encoding
Implementation
001
010
011
000
100
111
Implementation
D flip-flop for each state bit Combinational logic based on encoding
C3 0 0 0 0 1 1 1 1 N3
0 0 1 1 0
C2 0 0 1 1 0 0 1 1
C1 0 1 0 1 0 1 0 1 C3
1 1
N3 0 0 0 1 1 1 1 0
N2 0 1 1 0 0 1 1 0
N1 1 0 1 0 1 0 1 0 N2
0 1 0
N1 := C1' N2 := C1C2' + C1'C2 := C1 xor C2 N3 := C1C2C3' + C1'C3 + C2'C3 := C1C2C3' + (C1' + C2')C3 := (C1C2) xor C3
C3
1 0 0 1
N1
1 1 0 1 0
C3
1 0
C1
C1
C1
C2
C2
CS 150 - Spring 2007 Lec #6: Moore and Mealy Machines - 12
C2
Implementation (cont'd)
Programmable Logic Building Block for Sequential Logic
Macro-cell: FF + logic
D-FF Two-level logic capability like PAL (e.g., 8 product terms)
DQ Q
Another Example
Shift Register
Input determines next state
In 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 C1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 C2 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 C3 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 N1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
1 110 N2 N3 100 0 0 0 1 1 1 1 0 0 1 010 101 111 0 1 000 0 0 1 0 1 0 1 0 0 0 1 0 001 011 0 1 0 1 1 N1 := In 1 1 N2 := C1 0 0 N3 := C2 OUT1 OUT2 OUT3 0 0 0 1 0 1 D Q D Q D Q IN 1 0 CLK 1 0 1 1 CS 150 -1 Spring 2007 Lec #6: Moore and Mealy Machines - 14 1
Step 1: Derive the state transition diagram Step 2: Derive the state transition table from the state transition diagram
Present State Next State C B A C+ B+ A+ 0 0 0 0 1 0 0 0 1 0 1 0 0 1 1 010 101 0 1 1 1 0 1 1 0 0 011 1 0 1 1 1 0 1 1 0 0 0 0 note the don't care conditions that arise from the unused state codes 1 1 1 000 110
CS 150 - Spring 2007 Lec #6: Moore and Mealy Machines - 15
C
X 1
B+
1 1 0 0 X
C
X 1
A+
0 1 1 0 X
C
X 0
C
0 1
B+
1 1 0 0 0
C
1 1
A+
0 1 1 0 0
C
0 0
001
Self-Starting Counters
Start-up States Self-starting Solution
At power-up, counter may be in an unused or invalid state Designer must guarantee it (eventually) enters a valid state Design counter so that invalid states eventually transition to a valid state May limit exploitation of don't cares
111 000 100 010 011
CS 150 - Spring 2007 Lec #6: Moore and Mealy Machines - 18
001
001
010 011
101
Inputs
Ant Brain
Ant Behavior
A: Following wall, touching Go forward, turning left slightly B: Following wall, not touching Go forward, turning right slightly
C: Break in wall Go forward, turning right slightly E: Wall in front Turn left until...
C (TR, F)
Define next state function for each state variable Define output function for each output
2-level logic (ROM/PLA/PAL) Multi-level logic Next state and output functions can be optimized together
L R
TR, F
Synthesis
5 states : at least 3 state variables required (X, Y, Z)
State assignment (in this case, arbitrarily chosen)
LOST - 000 E/G A state L R X,Y,Z 000 0 0 000 0 1 ... ... ... 010 0 0 010 0 1 010 1 0 010 1 1 011 0 0 011 0 1 next state X', Y', Z' 000 001 ... 011 010 001 001 100 010 outputs F TR TL 1 0 1 0 ... 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 0 0 0 0 it now remains to synthesize these 6 functions B C - 001 - 010 - 011 - 100
Circuit Implementation
Outputs are a function of the current state only - Moore machine
F TR TL
Current State
Verilog Sketch
module ant_brain (F, TR, TL, L, R) inputs L, R; outputs F, TR, TL; reg X, Y, Z; assign F = function(X, Y, Z, L, R); assign TR = function(X, Y, Z, L, R); assign TL = function(X, Y, Z, L, R); always @(posedge clk) begin X <= function (X, Y, Z, L, R); Y <= function (X, Y, Z, L, R); Z <= function (X, Y, Z, L, R); end endmodule
If states can't happen, then don't care what the functions do if states do happen, we may be in trouble
L R 000 (F) 101 L+R 001 (TL) L R 011 (TR, F) 111 R L R 110 L+R L 010 (TL, F) R 100 (TR, F) L R
State Minimization
Fewer states may mean fewer state variables High-level synthesis may generate many redundant states Two state are equivalent if they are impossible to distinguish from the outputs of the FSM, i. e., for any input sequence the outputs are the same Two conditions for two states to be equivalent:
1) Output must be the same in both states 2) Must transition to equivalent states for all input combinations
C (TR, F)
X+
X 0 0 0 0 1 0 0 0 Y 1 1 1 1 1 1 0 0 R
Y+
X 0 1 1 1 1 0 0 0 Y 1 0 0 1 1 0 1 1 R
TR
X 0 0 0 0 0 0 0 0 Y 1 1 1 1 0 0 0 0 R
TL
X 0 0 0 0 1 1 1 1 Y 0 0 0 0 1 1 1 1 R