Beruflich Dokumente
Kultur Dokumente
Meyer
Module 3
Learning Outcome: An ability to analyze and design sequential logic circuits
A. B. C. D. E. F. Bi-stable Elements BiSetSet -Reset (S(S-R) and Data (D) Latches Data (D) and Toggle (T) FlipFlip-Flops State Machine Structure and Analysis Clocked Synchronous State Machine Synthesis State Machine Design Examples: Sequence Generators G. State Machine Design Examples: Counters and Shift Registers H. State Machine Design Examples: Sequence Recognizers
6
Outline
Overview Finite state machines Clock signal properties Types of sequential circuits BiBi -stable elements Digital analysis Analog analysis Metastable behavior
9
Overview
Logic circuits are classified into two types: a combinational logic circuit is one whose outputs depend only on its current inputs a sequential logic circuit is one whose outputs depend not only on its current inputs, but also its current state (arrived at by its past sequence of inputs) The state of a sequential circuit is a collection of state variables whose values at any one time contain all the information about the past necessary to account for the circuits future behavior
10
11
13
This element has no inputs and therefore no way of controlling or changing its state When power is first applied, it randomly comes up in one state or the other and stays there forever (not very useful)
15
The feedback loop is in equilibrium if the input and output voltages of both inverters are constant DC values consistent with their transfer functions
17
Analog Analysis
Vin1 Vin2
Vout1
Vout2
Vout1
Vin1 flip
Vin2
18
Metastable Behavior
The metastable point is not truly stable, because random noise will tend to drive a circuit operating at the metastable point toward one of the stable operating points
20
Metastable Behavior
Metastable behavior of a bistable can be compared to the behavior of a ball dropped onto a hill: if ball is dropped from overhead, it will probably roll down immediately to one side of the hill or the other if ball lands right at the top, it may sit there a while before random forces start it rolling
21
Metastable Behavior
Important: If the simplest sequential circuit is susceptible to metastable behavior, you can be sure that all sequential circuits are susceptible (and it is not something that only occurs at power-up) Consider what happens if we try to kick the ball from side of the hill to the other:
22
Metastable Behavior
Important: If the simplest sequential circuit is susceptible to metastable behavior, you can be sure that all sequential circuits are susceptible (and it is not something that only occurs at power-up) Consider what happens if we try to kick the ball from side of the hill to the other: clueless clip art
23
Metastable Behavior
Important: If the simplest sequential circuit is susceptible to metastable behavior, you can be sure that all sequential circuits are susceptible (and it is not something that only occurs at power-up) Consider what happens if we try to kick the ball from side of the hill to the other:
Raul
24
Outline
Overview SetSet -Reset (S (S-R) latch Basic operation Timing charts Normal operation Response to 11-1 input combination Response to a glitch/hazard Propagation delays Input pulse width Variants S-R latch S-R latch with enable Characteristic equation Data (D) latch Propagation delays Setup and hold times
27
Overview
Definition: A latch is a sequential circuit that Definition: watches all of its inputs continuously and changes its outputs at any time When a latch is enabled, it is open (i.e., its outputs follow its inputs) When a latch is disabled (its enable input is negated), it is closed (i.e., its outputs are frozen or latched latched) ) This behavior lends itself to the names data following and transparent Note: Note : Latches do not utilize a clocking signal; rather, they are enabled to open/close
28
S-R Latch
An S-R (set-reset) latch based on NOR gates can be implemented as follows:
It has a set (S) input and a reset (R) input and two outputs (Q and QN) that are normally complements of each other
29
S-R Latch
Asserting S sets (presets) the Q output to 1 Asserting R resets (clears) the Q output to 0 If both S and R are 0, the circuit behaves like the bistable element a feedback loop retains one of two logic states, Q = 0 or Q = 1
30
S-R Latch
31
S-R Latch
If both S and R are 1, 1 both outputs go LOW; if both S and R return to 0 simultaneously, the circuit goes to a random next state
32
Exercise
Construct a timing chart for the S-R latch Solution: Start by writing next state equations that describe the circuit, and from them construct a present state - next state table Q(t+) = R(t)QN(t) QN(t+) = S(t)Q(t)
33
Exercise
Next State
Exercise
00 SR Q QN 10
01
11
35
Exercise
01 00
01
10
Exercise
01 00
01
00, 01
10
Exercise
From the PS-NS table, construct a state transition diagram 10,11 11 00 SR Q QN 01,11 10 00,10
38
01 00
01
00, 01
10
11
Exercise
From the PS-NS table, construct a state transition diagram 10,11 11 00 SR Q QN 01,11 10 00,10
39
01 00
01
00, 01
10
dd 11
Exercise
QN
40
Exercise
QN
Initial Conditions
41
Exercise
QN
Initial Conditions
42
Exercise
QN
Initial Conditions
43
Exercise
QN
Initial Conditions
44
Exercise
QN
45
Exercise
QN
46
Exercise
QN
47
Exercise
QN
48
Exercise
QN
49
Exercise
QN
50
Exercise
QN
51
Exercise
QN
52
Exercise
QN
53
Exercise
QN
54
Exercise
QN
55
Exercise
QN
56
Exercise
QN
57
Exercise
QN
58
Exercise
QN
59
Exercise
Note the propagation delays tPLH
S
QN
tPHL
60
Exercise
Note the propagation delays tPLH tPLH
S
QN
tPHL
tPHL
61
Exercise
Note the propagation delays tPLH tPLH
S
QN
tPHL
tPHL
tPLH = 2 x tPHL
62
Exercise
QN
63
Exercise
QN
Initial Conditions
64
Exercise
QN
Initial Conditions
65
Exercise
QN
Initial Conditions
66
Exercise
QN
67
Exercise
QN
68
Exercise
QN
69
Exercise
QN
70
Exercise
QN
71
Exercise
QN
72
Exercise
QN
73
Exercise
QN
74
Exercise
QN
75
Exercise
QN
76
Exercise
QN
77
Exercise
QN
78
Exercise
QN
79
Exercise
QN
80
Clicker Quiz
81
Q1. For the NOR-implemented SR latch, the following output combination cannot occur at any time: A. B. C. D. E. Q=0, QN=0 Q=0, QN=1 Q=1, QN=0 Q=1, QN=1 none of the above
82
Q2. If the input combination S=0, R=1 is applied to this circuit, the (steady state) output will be: A. B. C. D. E. Q=0, QN=0 Q=0, QN=1 Q=1, QN=0 Q=1, QN=1 none of the above
83
Q3. If the input combination S=1, R=0 is applied to this circuit, the (steady state) output will be: A. B. C. D. E. Q=0, QN=0 Q=0, QN=1 Q=1, QN=0 Q=1, QN=1 none of the above
84
Q4. If the input combination S=1, R=1 is applied to this circuit, the (steady state) output will be: A. B. C. D. E. Q=0, QN=0 Q=0, QN=1 Q=1, QN=0 Q=1, QN=1 none of the above
85
Exercise
QN
86
Exercise
QN
Initial Conditions
87
Exercise
QN
Initial Conditions
88
Exercise
QN
Initial Conditions
89
Exercise
QN
Initial Conditions
90
Exercise
QN
91
Exercise
QN
92
Exercise
QN
93
Exercise
QN
94
Exercise
QN
95
Exercise
QN
96
Exercise
QN
97
Exercise
QN
98
Exercise
QN
99
Exercise
QN
100
Exercise
QN
101
Exercise
QN
102
Exercise
QN
103
105
S-R Latch
An S-R S-bar, R-bar latch with active low set and reset inputs can be built using NAND gates
106
107
Exercise Complete the PS-NS table for an S-R latch and derive its characteristic equation S 0 0 0 0 1 1 1 1 R 0 0 1 1 0 0 1 1 Q Q* 0 0 1 1 0 0 1 0 0 1 1 1 0 d 1 d S Q Q
0 2 6 1 3 7
S
4
Q* = ______________________
108
Exercise Complete the PS-NS table for an S-R latch and derive its characteristic equation S 0 0 0 0 1 1 1 1 R 0 0 1 1 0 0 1 1 Q Q* 0 0 1 1 0 0 1 0 0 1 1 1 0 d 1 d S Q Q
0
S
6
0 1
R
0
3
d d
1 1
R
Q* = ______________________
109
Exercise Complete the PS-NS table for an S-R latch and derive its characteristic equation S 0 0 0 0 1 1 1 1 R 0 0 1 1 0 0 1 1 Q Q* 0 0 1 1 0 0 1 0 0 1 1 1 0 d 1 d S Q Q
0
S
6
0 1
R
0
3
d d
1 1
R
Q* = ______________________
110
Exercise Complete the PS-NS table for an S-R latch and derive its characteristic equation S 0 0 0 0 1 1 1 1 R 0 0 1 1 0 0 1 1 Q Q* 0 0 1 1 0 0 1 0 0 1 1 1 0 d 1 d S Q Q
0
S
6
0 1
R
0
3
d d
1 1
R
S + R'Q Q* = ______________________
111
Clicker Quiz
112
2 1 3
2 1
Q1. For the circuit shown, the following output combination cannot occur at any time: A. B. C. D. E. X=0, Y=0 X=0, Y=1 X=1, Y=0 X=1, Y=1 none of the above
A
2 1 3
2 1
114
Q2. If the input combination A=0, B=1 is applied to this circuit, the (steady state) output will be: A. B. C. D. E. X=0, Y=0 X=0, Y=1 X=1, Y=0 X=1, Y=1 unpredictable
A
2 1 3
2 1
115
Q3. If the input combination A=1, B=0 is applied to this circuit, the (steady state) output will be: A. B. C. D. E. X=0, Y=0 X=0, Y=1 X=1, Y=0 X=1, Y=1 unpredictable
A
2 1 3
2 1
116
Q4. If the input combination A=0, B=0 is applied to this circuit, followed immediately by the input combination A=1, B=1, the (steady state) output will be: A. B. C. D. E. X=0, Y=0 X=0, Y=1 X=1, Y=0 X=1, Y=1 unpredictable
A
2 1 3
2 1
117
Q5. If the propagation delay of each gate is 10 ns, the minimum length of time that (valid) input combinations need to be asserted in order to prevent metastable behavior is: A A. 10 ns X B. 20 ns C. 30 ns Y D. 40 ns B E. none of the above
2 3 1 2 3 1
118
Transparent D Latch
In situations where we simply need to store a bit of information, a D latch can be used
Note that a D latch is just an S-R latch, with D connected to the S input and D connected to the R input (this eliminates the troublesome 1-1 input combination)
119
Transparent D Latch
When the enable input C is asserted, the latch is said to be open and the path from the D input to the Q output is transparent hence the name transparent latch When the enable input C is negated, the latch closes the Q output retains its last value and no longer changes in response to D
120
121
122
Clicker Quiz
123
Q1. A D latch is called transparent because its output: A. B. C. D. is always equal to its input is equal to its input when the latch is closed is equal to its input when the latch is open changes state as soon as the latch is clocked E. none of the above
124
Reading Assignment:
DDPP 4th Ed., pp. 532532-535, 541541-542
Learning Objectives:
Draw a circuit for an edgeedge-triggered data (D) flip flip-flop and analyze its behavior Compare the response of a latch and a flipflip-flop to the same set of stimuli Define setup and hold time and determine their nominal values from a timing chart Determine the frequency and duty cycle of a clocking signal Identify latch and flipflip-flop propagation delay paths and determine their values from a timing chart Describe the operation of a toggle (T) flipflip-flop and analyze its behavior Derive a characteristic equation for any type of latch or 126 flipflip -flop
Outline
Overview Positive edgeedge-triggered D flip flip-flop Negative edgeedge-triggered D flip flip-flop D flipflip-flop characteristic equation D flipflip-flop setup and hold times D flipflip-flop with enable EdgeEdge -triggered T flip flip-flop T flipflip-flop characteristic equation FlipFlip -flop timing parameters Response of latch vs. flipflip-flop Summary
127
Overview
Definition: A flip flip-flop is a sequential circuit that samples its inputs and changes its outputs only at times determined by a clocking signal (CLK) FlipFlip -flops change state in response to the transition (edge) of a clocking signal positive positive-edge edge-triggered flip flip-flops change low-to to-high transition of a state on the low clocking signal negative negative-edge edge-triggered flip flip-flops change state on the high high-to to-low transition of a clocking signal
128
130
131
132
Clicker Quiz
133
134
Q1. The minimum number of gates needed to implement a positive edge-triggered D flip-flop using only 2-input NAND gates is: A. 8 B. 9 C. 10 D. 11 E. 12
135
Q2. The minimum number of gates needed to implement a negative edge-triggered D flip-flop using only 2-input NAND gates is: A. 8 B. 9 C. 10 D. 11 E. 12
136
Exercise Complete the PS-NS table for an D flip-flop and derive its characteristic equation D Q Q
0 2 1 3
D 0 0 1 1
Q Q* 0 0 1 0 0 1 1 1
Q* = ______________________
137
Exercise Complete the PS-NS table for an D flip-flop and derive its characteristic equation D Q Q
0 2
D 0 0 1 1
Q Q* 0 0 1 0 0 1 1 1
0
1
1 1
Q* = ______________________
138
Exercise Complete the PS-NS table for an D flip-flop and derive its characteristic equation D Q Q
0 2
D 0 0 1 1
Q Q* 0 0 1 0 0 1 1 1
0
1
1 1
Q* = ______________________
139
Exercise Complete the PS-NS table for an D flip-flop and derive its characteristic equation D Q Q
0 2
D 0 0 1 1
Q Q* 0 0 1 0 0 1 1 1
0
1
1 1
D Q* = ______________________
140
141
142
(b) EN T Q
(a)
(b) EN
EN T Q Q
T
T CLK
Copyright 2000 by Prentice Hall, Inc. Digital Design Principles and Practices, 3/e
T Q
CLK Q
Copyright 2000 by Prentice Hall, Inc. Digital Design Principles and Practices, 3/e
143
T CLK
144
Exercise Complete the PS-NS table for a T flip-flop and derive its characteristic equation T Q Q
0 2 1 3
T 0 0 1 1
Q Q* 0 0 1 1 0 1 1 0
Q* = ______________________
145
Exercise Complete the PS-NS table for a T flip-flop and derive its characteristic equation T Q Q
0
T 0 0 1 1
Q Q* 0 0 1 1 0 1 1 0
T
2
0 1
1 0
Q* = ______________________
146
Exercise Complete the PS-NS table for a T flip-flop and derive its characteristic equation T Q Q
0
T 0 0 1 1
Q Q* 0 0 1 1 0 1 1 0
T
2
0 1
1 0
Clicker Quiz
155
Q1. The duty cycle of the clocking signal is: A. 20% B. 33% C. 40% E. none of the above D. 67%
156
Q2. The nominal setup time provided for the D flip-flop is: A. 5 ns B. 10 ns C. 15 ns E. none of the above D. 20 ns
157
Q3. The nominal hold time provided for the D flip-flop is: A. 5 ns B. 10 ns C. 15 ns E. none of the above D. 20 ns
158
Q4. The clock pulse width provided for the D flip-flop is: A. 5 ns B. 10 ns C. 15 ns E. none of the above D. 20 ns
159
Q7. Metastable behavior of an edgetriggered D flip-flop can be caused by: A. violating its minimum setup time requirement B. violating its minimum hold time requirement C. violating its minimum clock pulse width requirement D. all of the above E. none of the above
162
163
164
Summary
Latches and flipflip-flops are the basic building blocks of virtually all sequential circuits a latch is a sequential device that watches all of its inputs continuously and changes its outputs at any time (independent of a clocking signal) a flip flip-flop is a sequential device that samples its inputs and changes its outputs only at times determined by a clocking signal Because the functional behavior of latches and flip flops is quite different, it is important to know which type is being used in a design
165
Reading Assignment:
DDPP 4th Ed., pp. 542542-553
Learning Objectives:
Identify the key elements of a clocked synchronous state machine: next state logic, state memory (flip(flipflops), and output logic Differentiate between Mealy and Moore model state machines, and draw a block diagram of each Analyze a clocked synchronous state machine realized as either a Mealy or Moore model
167
Outline
Overview State machine structure Moore machine Mealy machine State machine analysis Moore machine analysis Mealy machine analysis
168
Overview
State machine (or finite state machine) machine) is a generic name given to sequential circuits Clocked indicates that the flipflip-flops employ a CLOCK (CLK) input Synchronous means that all the flipflip-flops in the state machine use the same CLOCK signal Analysis means to analyze the behavior of a given state machine construct a PSPS-NS table derive PSPS-NS equations draw a state transition diagram draw a timing chart
169
Moore Machine
In a Moore machine, the outputs are only a function of the current state
171
Mealy Machine
In a Mealy machine, the outputs are a function of the current state as well as the current inputs
172
173
Exercise 1
Analyze the following Mealy state machine:
176
Exercise 1
Analyze the following Mealy state machine:
ENQ0 + ENQ0
177
Exercise 1
Analyze the following Mealy state machine:
ENQ0 + ENQ0
ENQ1 + EN(Q1Q0)
178
Exercise 1
Analyze the following Mealy state machine:
ENQ0 + ENQ0 ENQ0Q1
ENQ1 + EN(Q1Q0)
179
Exercise 1
STEP 1: Write the next state equations for each D flip-flop and the output logic function Q0* = ENQ0 + ENQ0 = EN Q0 Q1* = ENQ1 + EN(Q1 Q0)
MAX = ENQ0Q1
180
Exercise 1
STEP 2: Construct a PS-NS / O table
PS Q1 Q0 0 0 0 0 0 1 0 1 1 0 1 0 1 1 1 1
Exercise 1
STEP 3: Construct a Mealy state transition diagram EN
MAX Q1 Q0
182
Exercise 1
STEP 3: Construct a Mealy state transition diagram EN
MAX Q1 Q0
00
01
11
10
183
Exercise 1
STEP 3: Construct a Mealy state transition diagram EN
MAX Q1 Q0 0 0 00 0 0 01
11 0 0 0 0
10
184
Exercise 1
STEP 3: Construct a Mealy state transition diagram EN
MAX Q1 Q0 0 0 00 1 1 11 0 0 1 0 0 0 01 1 0 1 0 0 0
185
10
Exercise 1
STEP 4: Draw a timing chart
186
Exercise 1
STEP 4: Draw a timing chart
187
Exercise 1
STEP 4: Draw a timing chart
188
Exercise 1
STEP 4: Draw a timing chart
189
Exercise 1
STEP 4: Draw a timing chart
190
Exercise 2
Analyze the following Moore state machine:
191
Exercise 2
Analyze the following Moore state machine:
ENQ0 + ENQ0
192
Exercise 2
Analyze the following Moore state machine:
ENQ0 + ENQ0
ENQ1 + EN(Q1Q0)
193
Exercise 2
Analyze the following Moore state machine:
ENQ0 + ENQ0
Q0Q1
ENQ1 + EN(Q1Q0)
194
Exercise 2
STEP 1: Write the next state equations for each D flip-flop and the output logic function Q0* = ENQ0 + ENQ0 = EN Q0 Q1* = ENQ1 + EN(Q1 Q0)
MAXS = Q0Q1
195
Exercise 2
STEP 2: Construct a PS-NS / O table
PS Q1 Q0 0 0 0 0 0 1 0 1 1 0 1 0 1 1 1 1
Exercise 2
STEP 3: Construct a Moore state transition diagram
EN Q1 Q0 MAXS
197
Exercise 2
STEP 3: Construct a Moore state transition diagram EN
Q1 Q0 MAXS 00 0 01 0
11 1
10 0
198
Exercise 2
STEP 3: Construct a Moore state transition diagram EN
Q1 Q0 MAXS 0 00 0 0 01 0
11 1 0 0
10 0
199
Exercise 2
STEP 3: Construct a Moore state transition diagram EN
Q1 Q0 MAXS 0 00 0 1 0 01 0 1 1 11 1 0 10 0 0
200
Exercise 2
STEP 4: Draw a timing chart
201
Exercise 2
STEP 4: Draw a timing chart
202
Exercise 2
STEP 4: Draw a timing chart
203
Exercise 2
STEP 4: Draw a timing chart
204
Reading Assignment: DDPP 4th Ed., pp. 553553-566, 612612-625, 682 682-689 Learning Objectives:
Outline the steps required for state machine synthesis Derive the excitation table for any type of latch or flipflip-flop Discuss reasons why formal statestate-minimization procedures are seldom used by experienced digital system designers Describe three ways that state machines can be specified in ABEL: using a clocked truth table, using clocked assignment operators, or using a state diagram approach List the ABEL attribute suffixes that pertain to sequential circuits Draw a circuit for an oscillator and calculate its frequency of operation Draw a circuit for a bouncebounce-free switch based on an SS-R latch and analyze its behavior 206
Outline
Overview State machine design steps Derivation of flipflip-flop excitation tables Flip Flip-flop choice State machines in ABEL Attribute suffixes Macrocell structure Clocking considerations Periodic clock generation circuits Timing diagram and specifications Event clock generation circuits
207
Overview
Designing a finite state machine (FSM) is a creative process that is, in many ways, like writing a computer program: You have a fairly good idea of what the input and output signals should be, but perhaps an imprecise description of the desired relationship between them During the design you may have to identify and choose among different ways of doing things sometimes using common sense, sometimes arbitrarily You may have to identify and handle special cases that werent included in the original description
208
Overview
Creative process You will probably have to keep track of several ideas in your head during the design process Since the design process is not an algorithm, theres no guarantee that you can complete it using a finite number of states or lines of code When you finally run the state machine or program, it will do exactly what you told it to do no more, no less Theres no guarantee the thing will work the first time you may have to debug and iterate the entire process 209
210
Q Q* S 0 0 0 1 1 0 1 1
212
Q Q* S 0 0 0 0 1 1 0 1 1
R d
213
Q Q* S 0 0 0 0 1 1 1 0 1 1
R d 0
214
Q Q* S 0 0 0 0 1 1 1 0 0 1 1
R d 0 1
215
Q Q* S 0 0 0 0 1 1 1 0 0 1 1 d
R d 0 1 0
NOTE: Two excitation equations are required for each flip-flopprobably not desirable!
216
T 0 0 1 1
Q Q* 0 0 1 1 0 1 1 0
Q Q* 0 0 0 1 1 0 1 1
T 0
217
T 0 0 1 1
Q Q* 0 0 1 1 0 1 1 0
Q Q* 0 0 0 1 1 0 1 1
T 0 1
218
T 0 0 1 1
Q Q* 0 0 1 1 0 1 1 0
Q Q* 0 0 0 1 1 0 1 1
T 0 1 1
219
T 0 0 1 1
Q Q* 0 0 1 1 0 1 1 0
Q Q* 0 0 0 1 1 0 1 1
T 0 1 1 0
NOTE: Here, only one excitation equation is required for each flip-flop a common application is binary counters
220
D 0 0 1 1
Q Q* 0 0 1 0 0 1 1 1
Q Q* D 0 0 0 0 1 1 0 1 1
221
D 0 0 1 1
Q Q* 0 0 1 0 0 1 1 1
Q Q* D 0 0 0 0 1 1 1 0 1 1
222
D 0 0 1 1
Q Q* 0 0 1 0 0 1 1 1
Q Q* D 0 0 0 0 1 1 1 0 0 1 1
223
D 0 0 1 1
Q Q* 0 0 1 0 0 1 1 1
Q Q* D 0 0 0 0 1 1 1 0 0 1 1 1
NOTE: For D flip-flops, Q*=D, which means the excitation equation is identical to the next state equation, which makes synthesis using D flip-flops very straight-forward!
224
Clicker Quiz
226
E.
Q2. Designing a state machine based on minimum risk means: A. there are no hazards in the clocking signal B. there are no dont cares in the output equations C. there are no dont cares in the next state equations D. all of the above E. none of the above
228
Q3. An FSM design has 212 states; to reduce the number of flip-flops required by one, you would have to identify and eliminate _____ redundant state(s). A. B. C. D. E. 1 2 44 84 none of the above
229
C.
D. E.
231
Attribute Suffixes
ABEL allows three possible values on the rightright -hand side of an equation using an attribute suffix on the signal name .Q the actual flipflip-flop output pin before any programmable inversion .FB a value equal to the value that the output pin would have if enabled .PIN the actual signal at the PLD output pin (this signal is floating or may be used as an input if the tritri-state driver is not enabled)
233
Attribute Suffixes
ABEL allows equations to be written for other functions within a macrocell, again using attribute suffixes on the signal name: .D the flipflip-flop D input .CLK the flipflip-flop CLOCK input .OE the pin tritri-state buffer output enable .AP the flipflip-flop asynchronous preset (equivalent to the S input on an S R latch) .AR the flipflip-flop asynchronous reset (equivalent to the R input on an S R latch)
234
I/O pin
All OLMC edge-triggered D flip-flops utilize common clock (CLK) , asynchronous reset (AR), and asynchronous preset (SP) signals
235
I/O pin
4:1 multiplexer selects (routes) true/complemented combinational or true/complemented registered function to the I/O pin
236
I/O pin
2:1 multiplexer selects (routes) true/complemented I/O pin or true/complemented registered feedback to the P-term array
237
238
239
Clocking Considerations
State machines require a clocking signal in order to operate sequentially There are two basic types of clocking signals that can be used: periodic (continuously running), generated using an oscillator circuit event (non (non-periodic, single clock edge), generated using a bounce bounce-free switch or sensor contact closure A timing diagram can be used to show the relationship between the clock and various input, output, and internal signals it can also be used to help answer the key question facing computer system designers: How fast can this thing run?
240 240
241
OUTPUT
74HC04
74HC04
74HC04
C R1 R2
OUTPUT
74HC04
74HC04
R1 R2 C1 C2
Crystal
245
246
247
timing margin
251
252
253
254
255
256
L
257
H
258
H
259
H
260
H
261
H
262
L
263
L
264
L
265
Here, we are essentially using the D flip-flop as an S-R latch via its asynchronous preset (.AP) and asynchronous reset (.AR) inputs
Clicker Quiz
267
Q1. The next state equation represented by the following state transition diagram is: A. B. C. D. E. X* = AX + AX X* = AX + AX X* = A + X X* = AX none of the above
268
Q2. If designed for minimum cost, the next state equation for X is: A. B. C. D. E. X* = AY X* = X + Y X* = XY + AX X* = AY + XY none of the above
269
Q3. If designed for minimum cost, the next state equation for Y is: A. B. C. D. E. Y* = AY Y* = A + Y Y* = XY + AX Y* = AY + XY none of the above
270
272
Outline
Overview Simple character sequence display Dual mode moving dot / building dot sequence generator Moore model realizations Mealy model realizations Summary
273
Overview
A sequence generator state machine produces a (periodic) series of output signal assertions that constitute a pre pre-defined pattern: vehicle tail lights (e.g., TT-bird) traffic control signs (e.g., blinkers and stoplights) character displays (e.g., GO BOILERS) process control sequences (e.g., wash, rinse, dry) Either a Mealy or a Moore model can be used as the basis for designing a sequence generator Two different design strategies can be employed: minimum cost unused states are assumed to be dont cares, potentially reducing realization cost while increasing risk of undefined behavior if machine gets into an unknown (unused) state minimum risk unused states are explicitly assigned a next state, eliminating risk of undefined behavior but potentially increasing realization cost 274
275
A = 1110111
277
A = 1110111 b = 0011111
278
00
A = 1110110
0 1
01
b = 0011111
0 0 0 1
11
S = 1011011 1
10
C = 1001110
00
A = 1110110
0 1
01
b = 0011111
0 0 0 1
11
S = 1011011 1
10
C = 1001110
MODULE tv_disp TITLE 'Character Sequence Display' DECLARATIONS CLOCK pin; M pin; " mode control Q1..Q0 pin istype 'reg'; " 7-segment display outputs (common anode, active low) !LA,!LB,!LC,!LD,!LE,!LF,!LG pin istype 'com'; TRUTH_TABLE ([Q1, [ 0, [ 0, [ 1, [ 1, Q0] 0 ] 1 ] 0 ] 1 ] -> -> -> -> -> M] 0] 1] 0] 1] 0] 1] 0] 1] [LA, LB, LC, LD, LE, LF, LG]) [ 1, 1, 1, 0, 1, 1, 0]; [ 0, 0, 1, 1, 1, 1, 1]; [ 1, 0, 0, 1, 1, 1, 0]; [ 1, 0, 1, 1, 0, 1, 1]; :> :> :> :> :> :> :> :> :> [Q1, Q0]) [ 0, 1]; [ 1, 0]; [ 1, 0]; [ 1, 1]; [ 0, 0]; [ 0, 1]; [ 0, 0]; [ 1, 0];
A b C S
283
STATE L2 L1 L0
289
00
00
D 001
00
B 100 C 010
00
290
00
A 000
00
01
D 001
01 00
B 100
00
C 010
01
291
00
A 000
00,10
01
10
D 001
01 00
B 100 C 010
01 00 10
F 111
10
E 110
292
A 000
00,10
01
10
H 111
11
11 01
D 001
00
B 100 C 010
01 00 10
F 111
10
G 011
E 110
293
A 000
00,10
01
10,11
H ??? G 011
11 01
D 001
00
B 100 C 010
01 00 10
F 111
10
E 110
294
11
000 000
11 01
011 001
00
00,10 B
01
10,11
001 100
10
101 111
E 10
010 010
01
00
100 110
295
11
296
297
MODULE moorelsA TITLE 'Light Sequencer Moore Model A' DECLARATIONS CLOCK pin; M0, M1 pin; Q2, Q1, Q0 pin istype 'reg'; L2, L1, L0 pin istype 'com'; truth_table ([Q2,Q1,Q0,M1,M0]:>[Q2,Q1,Q0]) [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1]; 1]; 1]; 1]; 0]; 0]; 0]; 0]; 1]; 1]; 0]; 0]; 0]; 0]; 0]; 0];
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1,
0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0]; 0]; 1]; 0]; 0]; 0]; 0]; 0]; 0]; 0]; 0]; 1]; 0]; 0]; 0]; 0];
truth_table ([Q2,Q1,Q0]->[L2,L1,L0]) [ 0, 0 ,0]->[ 0, 0, 0]; [ 0, 0, 1]->[ 1, 0, 0]; [ 0, 1, 0]->[ 0, 1, 0]; [ 0, 1, 1]->[ 0, 0, 1]; [ 1, 0, 0]->[ 1, 1, 0]; [ 1, 0, 1]->[ 1, 1, 1]; [ 1, 1, 0]->[ 0, 1, 1]; [ 1, 1, 1]->[ 0, 0, 0]; EQUATIONS [Q2..Q0].CLK = CLOCK; END
298
Revisit Steps 2 & 3: Did we pick the best state/output assignments possible?
000
00: Dot L R
100 010
001
299
Revisit Steps 2 & 3: Did we pick the best state/output assignments possible?
000 00 00 00 010 00
00: Dot L R
100
001
300
Revisit Steps 2 & 3: Did we pick the best state/output assignments possible?
01 00
00: Dot L R
001 01
301
Revisit Steps 2 & 3: Did we pick the best state/output assignments possible?
10 110 000 10 100 01 111 10 01
00: Dot L R
00,10 00 00 00 01 010
001 01
302
Revisit Steps 2 & 3: Did we pick the best state/output assignments possible?
10 110 111 10,11 000 10 100 01 01,11 11 001 01 01 010
00: Dot L R 01: Dot L R 10: Build L R 11: Build L R
11 011
00,10 00 00 00
303
Revisit Steps 2 & 3: Did we pick the best state/output assignments possible?
10 110 dd 10 100 01 101 111 10,11 000 01,11 11 001 01 01 010
00: Dot L R 01: Dot L R 10: Build L R 11: Build L R
11 011
00,10 00 00 00
304
MODULE moorelsB TITLE 'Light Sequencer Moore Model B' DECLARATIONS CLOCK pin; M0, M1 pin; Q2, Q1, Q0 pin istype 'reg'; "(serve as L2, L1, L0) truth_table ([Q2,Q1,Q0,M1,M0]:>[Q2,Q1,Q0]) [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0]; 1]; 0]; 1]; 0]; 0]; 0]; 1]; 1]; 0]; 0]; 0]; 0]; 0]; 0]; 1];
Note: Here the output functions are merely the state variables L2=Q2, L1=Q1, L0=Q0
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1,
0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0]; 0]; 0]; 0]; 0]; 0]; 0]; 0]; 0]; 0]; 0]; 0]; 0]; 0]; 0]; 0];
305
MODULE moorelsB_sd TITLE 'Light Sequencer Using State Diagram' M1, M0 pin; CLOCK pin; Q2, Q1, Q0 pin istype 'reg'; QALL A0 A1 A2 A3 A4 A5 A6 A7 = = = = = = = = = [Q2,Q1,Q0]; [ 0, 0, 0]; [ 0, 0, 1]; [ 0, 1, 0]; [ 0, 1, 1]; [ 1, 0, 0]; [ 1, 0, 1]; [ 1, 1, 0]; [ 1, 1, 1];
state A3:
A0 A0 A0 A7; A2 A0 A6 A0;
state A4:
state A5: goto A0; state A6: then then then then then then then then then then then then A4 A1 A4 A1; A0 A2 A0 A3; A1 A4 A0 A0; if else if else if else if if else if else if else if (M1==0)&(M0==0) (M1==0)&(M0==1) (M1==1)&(M0==0) (M1==1)&(M0==1) (M1==0)&(M0==0) (M1==0)&(M0==1) (M1==1)&(M0==0) (M1==1)&(M0==1) then then then then then then then then A0 A0 A7 A0; A0 A0 A0 A0;
STATE_DIAGRAM QALL state A0: if else if else if else if if else if else if else if if else if else if else if (M1==0)&(M0==0) (M1==0)&(M0==1) (M1==1)&(M0==0) (M1==1)&(M0==1) (M1==0)&(M0==0) (M1==0)&(M0==1) (M1==1)&(M0==0) (M1==1)&(M0==1) (M1==0)&(M0==0) (M1==0)&(M0==1) (M1==1)&(M0==0) (M1==1)&(M0==1)
state A7:
state A1:
state A2:
STATE NAME
308
309
D
00 010
B
00 100
310
A
00 001
00 000 01 100
D
01 001 00 010
B
00 100
C
01 010
311
00 000
10 000 01 100
01 001
D
00 , 10 010 110
B
00 , 10 100 100
C
01 010
312
00 000
D
01 , 11 001 001 00 , 10 010 110
B
00 , 10 100 100
01 , 11 010 011
313
STEP 2: Minimize the number of states STEP 3: Assign state variable combinations
d1 000 00 , 10 001 111 00 d0 000 01 , 11 100 111 01 d0 100 10 01 , 11 010 011
314
315
MODULE mealylsa truth_table ([Q1,Q0,M1,M0]->[L2,L1,L0]) TITLE 'Light Sequencer - Mealy Model A' DECLARATIONS CLOCK pin; M0, M1 pin; Q1, Q0 pin istype 'reg'; L2, L1, L0 pin istype 'com'; truth_table ([Q1,Q0,M1,M0]:>[Q1,Q0]) [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1]; 1]; 1]; 1]; 0]; 0]; 0]; 0]; 1]; 1]; 1]; 1]; 0]; 0]; 0]; 0]; [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0]; 0]; 0]; 0]; 0]; 0]; 0]; 1]; 0]; 0]; 0]; 1]; 1]; 1]; 1]; 1];
316
Revisit Steps 2 & 3: Did we pick the best state/output assignments possible?
00 001
00
01 100
1d 111
dd 000
11
01
d0 100
0d 010
10 110
d1 001
11 011
10
317
318
MODULE mealylsb truth_table ([Q1,Q0,M1,M0]->[L2,L1,L0]) TITLE 'Light Sequencer - Mealy Model B' DECLARATIONS CLOCK pin; M0, M1 pin; Q1, Q0 pin istype 'reg'; L2, L1, L0 pin istype 'com'; truth_table ([Q1,Q0,M1,M0]:>[Q1,Q0]) [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0]:>[ 1]:>[ 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1]; 1]; 1]; 1]; 0]; 0]; 0]; 0]; 1]; 1]; 1]; 1]; 0]; 0]; 0]; 0]; [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0]; 0]; 0]; 0]; 0]; 1]; 0]; 1]; 0]; 0]; 0]; 1]; 1]; 0]; 1]; 1];
319
MODULE mealylsb_sd TITLE 'Mealy Model Implemented with State Diagram' DECLARATIONS M0, M1 pin; CLOCK pin; Q1, Q0 pin istype 'reg'; L2, L1, L0 pin istype 'com'; " State definitions QALL = [Q1,Q0]; A0 = [ 0, 0]; A1 = [ 0, 1]; A2 = [ 1, 0]; A3 = [ 1, 1]; state_diagram QALL state state state state A0: A1: A2: A3: goto goto goto goto A1; A2; A3; A0;
EQUATIONS
truth_table ([Q1,Q0,M1,M0]->[L2,L1,L0]) [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0]; 0]; 0]; 0]; 0]; 1]; 0]; 1]; 0]; 0]; 0]; 1]; 1]; 0]; 1]; 1];
320
Clicker Quiz
321
MODULE MCLEDS TITLE 'Multi-Color LED Light Machine' DECLARATIONS M pin; " mode control input Q0..Q1 pin istype 'reg'; " state variables R,G,Y,B pin istype 'com'; " LEDs (red/green/yellow/blue) CLOCK pin; TRUTH_TABLE([Q1,Q0, [ 0, 0, [ 0, 0, [ 0, 1, [ 0, 1, [ 1, 0, [ 1, 0, [ 1, 1, [ 1, 1, TRUTH_TABLE([Q1,Q0, [ 0, 0, [ 0, 0, [ 0, 1, [ 0, 1, [ 1, 0, [ 1, 0, [ 1, 1, [ 1, 1, M]:>[Q1,Q0]) 0]:>[ 1, 0]; 1]:>[ 1, 1]; 0]:>[ 1, 1]; 1]:>[ 0, 0]; 0]:>[ 0, 1]; 1]:>[ 0, 1]; 0]:>[ 0, 0]; 1]:>[ 1, 0]; M]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ 0]->[ 1]->[ R, 1, 1, 0, 1, 0, 1, 0, 1, G, 0, 0, 0, 1, 1, 1, 0, 1, Y, 0, 0, 1, 1, 0, 1, 0, 0, B]) 0]; 0]; 0]; 1]; 0]; 0]; 1]; 0];
322
Q1. When M=0, the (repeating) colored LED sequence produced will be: A. B. C. D. E. RGYB RYGB BYGR BGYR none of the above
323
Q2. When M=1, the (repeating) colored LED sequence produced will be: A. B. C. D. E. RRGYBRGYRG RRGRGYRGYB RGYBRGYRGR RRGYRGRGYB none of the above
324
Summary
The choice of model (Mealy vs. Moore) can have a significant impact on the complexity of the realization and PLD resources (macrocells (macrocells) ) consumed The state assignment strategy employed can make a significant difference difference in the amount of work required Obvious state minimization can also sometimes be useful (formal statestate-minimization procedures are seldom used by most digital designers, however) The only formal way to find the best state assignment is to try all the assignments thats too much work (even for students)! To do this well, we need experience as well as have knowledge of some practical guidelines (see text) There is no substitute for practice in designing state machines much of engineering is applied intuition, and this is a good example of it! 325
Module 3-G State Machine Design Examples: Counters and Shift Registers
326
Reading Assignment: DDPP 4th Ed., pp. 710710-721, 727727-736 Learning Objectives:
Compare and contrast the operation of binary and shift register counters Derive the next state equations for binary up and down counters Describe the feedback necessary to make ring and Johnson counters selfself-correcting Compare and contrast state decoding for binary and shift register counters Describe why glitches occur in some state decoding strategies and discuss how to eliminate them
327
Outline
Overview Binary counter registers UP and DOWN counter derivations Basic binary counter extensions ENABLE input ASYNCHRONOUS RESET UP and DOWN count modes Synchronously resettable counters SYNCHRONOUS RESET MODULUS control Shift register counters State decoding Summary
328
Overview
Definition: The name counter is used for Definition: any clocked sequential circuit whose state diagram contains a single cycle
Definition: A register is a collection of two Definition: or more flipflip-flops with a common clock and, generally, a common purpose
329
334
MODULE count8u TITLE 'Basic 8-bit Binary UP Counter' DECLARATIONS Q0..Q7 pin istype 'reg'; CLOCK pin; EQUATIONS Q0 := !Q0; Q1 := Q1 $ Q2 := Q2 $ Q3 := Q3 $ Q4 := Q4 $ Q5 := Q5 $ Q6 := Q6 $ Q7 := Q7 $
339
MODULE count8d TITLE 'Basic 8-bit Binary DOWN Counter' DECLARATIONS Q0..Q7 pin istype 'reg'; CLOCK pin; EQUATIONS Q0 := !Q0; Q1 := Q1 $ Q2 := Q2 $ Q3 := Q3 $ Q4 := Q4 $ Q5 := Q5 $ Q6 := Q6 $ Q7 := Q7 $
341
MODULE cnt8ud TITLE '8-bit Binary UP/DOWN Counter' DECLARATIONS Q0..Q7 pin istype 'reg'; M, CLOCK pin; " M=0 count DOWN, M=1 count UP EQUATIONS Q0 := !Q0; Q1 := Q1 $ Q2 := Q2 $ Q3 := Q3 $ Q4 := Q4 $ Q5 := Q5 $ Q6 := Q6 $ Q7 := Q7 $
(M&Q0 # !M&!Q0); (M&Q1&Q0 # !M&!Q1&!Q0); (M&Q2&Q1&Q0 # !M&!Q2&!Q1&!Q0); (M&Q3&Q2&Q1&Q0 # !M&!Q3&!Q2&!Q1&!Q0); (M&Q4&Q3&Q2&Q1&Q0 # !M&!Q4&!Q3&!Q2&!Q1&!Q0); (M&Q5&Q4&Q3&Q2&Q1&Q0 # !M&!Q5&!Q4&!Q3&!Q2&!Q1&!Q0); (M&Q6&Q5&Q4&Q3&Q2&Q1&Q0 # !M&!Q6&!Q5&!Q4&!Q3&!Q2&!Q1&!Q0);
342
MODULE count8er TITLE '8-bit Binary UP Counter with ENABLE and Asynchronous Reset' DECLARATIONS Q0..Q7 pin istype 'reg'; CLOCK pin; EN pin; ARESET pin; " If EN=0, stays in same state " If EN=1, counts UP " If ARESET asserted, resets to 00...0 (regardless of whether or not enabled) EQUATIONS Q0 := !EN&Q0 Q1 := !EN&Q1 Q2 := !EN&Q2 Q3 := !EN&Q3 Q4 := !EN&Q4 Q5 := !EN&Q5 Q6 := !EN&Q6 Q7 := !EN&Q7
# # # # # # # #
Clicker Quiz
344
1 000 0 0 001
1 010 0
1 011 0 1
1 111
0 110 1
0 101 1
0 100 1 0
345
Module CQ Title Program (A) DECLARATIONS CLOCK, M pin; Q0..Q2 pin istype reg; EQUATIONS Q0 := !Q0; Q1 := !Q1 $ (!M&!Q0 # M&Q0); Q2 := !Q2 $ (!M&!Q1&!Q0 # M&Q1&Q0); [Q2..Q0].CLK = CLOCK; END Module CQ Title Program (B) DECLARATIONS CLOCK, M pin; Q0..Q2 pin istype reg; EQUATIONS Q0 := !Q0; Q1 := Q1 $ (!M&Q0 # M&!Q0); Q2 := Q2 $ (!M&Q1&Q0 # M&!Q1&!Q0); [Q2..Q0].CLK = CLOCK; END
Module CQ Title Program (C) DECLARATIONS CLOCK, M pin; Q0..Q2 pin istype reg; EQUATIONS Q0 := !Q0; Q1 := Q1 $ (!M&!Q0 # M&Q0); Q2 := Q2 $ (!M&!Q1&!Q0 # M&Q1&Q0); [Q2..Q0].CLK = CLOCK; END Module CQ Title Program (D) DECLARATIONS CLOCK, M pin; Q0..Q2 pin istype reg; EQUATIONS [Q2..Q0] := [Q2..Q0] + 1 [Q2..Q0].CLK = CLOCK; END (E) None of the above 346
Resettable Counters
In addition to an asynchronous reset (which allows to the counter to be placed in a known initial state), it is sometimes useful to provide a synchronous reset capability Such a counter is useful in applications where the number of states in the counting sequence is determined dynamically Example: Example : State counter in a computers execute unit, where the number of cycles necessary to complete an instruction varies Another variation: variation: Counter with a programmable final state (modulo M)
347
MODULE rcnt8u TITLE 'Resettable 8-bit Binary UP Counter' DECLARATIONS Q0..Q7 pin istype 'reg'; R, CLOCK pin; " if R=1, next state will be 00...0 EQUATIONS Q0 := !R & Q1 := !R & Q2 := !R & Q3 := !R & Q4 := !R & Q5 := !R & Q6 := !R & Q7 := !R &
MODULE mrcnt8ud TITLE 'Modulo Resettable 8-bit Binary UP Counter' DECLARATIONS Q0..Q7 pin istype 'reg'; D0..D7 pin; CLOCK pin; R pin istype 'com'; " Counts UP to value input on D7..D0; next state is 00...0 EQUATIONS R = !(D0$Q0) & !(D1$Q1) & !(D2$Q2) & !(D3$Q3) & !(D4$Q4) & !(D5$Q5) & !(D6$Q6) & !(D7$Q7); Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 := := := := := := := := !R !R !R !R !R !R !R !R & & & & & & & & !Q0; (Q1 $ (Q2 $ (Q3 $ (Q4 $ (Q5 $ (Q6 $ (Q7 $
MODULE ring4 TITLE 'Simple 4-bit Ring Counter' " Assertion of R causes next state " of ring counter to be 0001 DECLARATIONS CLOCK pin; R pin; " synchronous reset Q0..Q3 pin istype 'reg'; EQUATIONS
Initial state
MODULE ring4 TITLE 'Simple 4-bit Ring Counter' " Assertion of R causes next state " of ring counter to be 0001 DECLARATIONS CLOCK pin; R pin; " synchronous reset Q0..Q3 pin istype 'reg'; EQUATIONS
R=0 R=0
R=0
352
MODULE ring4 TITLE 'Simple 4-bit Ring Counter' " Assertion of R causes next state " of ring counter to be 0001 DECLARATIONS CLOCK pin; R pin; " synchronous reset Q0..Q3 pin istype 'reg';
R=1 EQUATIONS
355
Johnson Counters
Definition: An nDefinition: n-bit shift register with the complement of the serial output fed back into the serial input is a counter with 2n states and is called a switchtail, twisted twisted-ring, or Johnson counter Problem: Problem : A Johnson counter has the same robustness problem that the simple ring counter has Solution: Solution : Make it self self-correcting by using appropriate feedback, here to load 0001 as the next state whenever the current state is 0dd0 (or, for an n-bit counter, when the current state is 0dd0) 357
0000 0001
0011
1100
1011
0100
0111 1111
1110
0110 1101
1010
0101
1101
1011
1010
0110
0100
0011
1100
0111 1111
1110
359
State Decoding
What is needed to decode the states of an n-bit (n state) ring counter? Nothing just use state variables directly
360
S1 = Q0 S2 = Q1 S3 = Q2 S4 = Q3
361
State Decoding
What is needed to decode the states of an n-bit (n state) ring counter? Nothing just use state variables directly What is needed to decode the states of an n-bit (2n state) Johnson counter? 2n 2-input AND or NAND gates
362
S1 = Q0 Q3 S2 = Q0 Q1 S3 = Q1 Q2 S4 = Q2 Q3
S5 = Q0 Q3 S6 = Q0 Q1 S7 = Q1 Q2 S8 = Q2 Q3
363
MODULE john4scd TITLE 'Self-Correcting 4-bit Johnson Counter with Decoded Outputs' " Loads 0001 as next state when current state is 0xx0 DECLARATIONS CLOCK pin; Q0..Q3 pin istype 'reg'; S1..S8 pin istype 'com'; " decoded outputs (text, p. 728) R = !Q3&!Q0; " match 0xx0 EQUATIONS Q3 := !R&Q2; Q2 := !R&Q1; Q1 := !R&Q0; Q0 := !R&!Q3 # R; [Q0..Q3].CLK = CLOCK; S1 S2 S3 S4 S5 S6 S7 S8 = = = = = = = = !Q3 !Q1 !Q2 !Q3 Q3 Q1 Q2 Q3 & & & & & & & & !Q0; Q0; Q1; Q2; Q0; !Q0; !Q1; !Q2;
state decoding
END
364
State Decoding
What is needed to decode the states of an n-bit (n state) ring counter? Nothing just use state variables directly What is needed to decode the states of an n-bit (2n state) Johnson counter? 2n 2-input AND or NAND gates How does this compare with decoding the states of an nn-bit (2n state) binary counter? Need 2n n-input AND or NAND gates, where n is the number of state variables (or, an n-to-2n decoder)
365
State Decoding
Problem: Because more than one bit Problem: position changes simultaneously in a binary count sequence, there will be glitches in the decoded outputs Solution: Solution : Connect the decoder outputs to a register that samples the stable decoded outputs on the next clock tick
366
367
Thought Questions
Give an example of an application where state decoding glitches can cause problems When decoded outputs are used as clocking signals Given that 8 glitchglitch-free decoded outputs are required for a given application, which solution would be best: a 33-bit binary counter, decoder, and dede-glitching register; or a 44-bit self self-correcting Johnson counter? Johnson counter
368
Thought Questions
Is it possible to construct an n-bit counter with 2n states that can be decoded in a glitchglitch -free fashion? YES a Gray-code counter If so, what property should the count sequence possess? Each successive combination should differ in only a single bit position
369
Thought Questions
Where have we seen this before? On K-maps! Q2 Q0 Q0
0 2 6
Q2
4
Q1
Q1
Q1
Summary
Counters are a common building block used in sequential circuit design, particularly with sequence generator state machines There are two basic types of counters binary shift register (types differ based on feedback) Counter states can be decoded different ways (some are glitchglitch-free, others are not) binary: standard decoders, not glitchglitch-free Johnson: 22-input AND gates, glitch glitch-free ring: nothing (use flipflip-flop outputs directly), glitchglitch -free
371
373
Outline
Overview Simple pattern recognizer Digital lock Summary
374
Overview
A sequence recognizer state machine responds to a prepre -defined input pattern of signal assertions and produces corresponding output signal assertions digital lock / access code control bit sequence detector Use of Moore models to design sequencer recognizer is generally preferred preferred, , because you typically dont want any output signals to change (based on input signal changes) until the machine is clocked to the next state (i.e., the outputs should only be a function of the state variables) Because action (output signal assertions) occur in response to a prepre-defined pattern, a sequence recognizer has different kinds of final states (denoted with concentric circles on ST diagram): final state of accepting sequence (e.g., unlock) trap state (e.g., alarm)
375
RX
Q2 Q1 Q0 ------------L U A
Combination: 101110
000 100
LOCKED
001 000
010 000
011 000
111 001
ALARM
110 010
UNLOCKED
101 000
100 000
380
RX
Q2 Q1 Q0 ------------L U A
Combination: 101110
000 100
01
001 00 000
010 000
01
011 000 01
111 001
110 010
101 00 000
100 01 000
381
RX
Q2 Q1 Q0 ------------L U A
Combination: 101110 1d 000 100 01 001 00 000 1d 010 000 01 1d 011 000 01 111 001 0d 110 010 1d 101 00 000 1d 100 01 000 1d
382
1d
RX
Q2 Q1 Q0 ------------L U A
Combination: 101110 1d 000 100 00 01 001 00 000 01 1d 010 000 00 01 111 001 0d 110 010 1d 101 00 000 1d 01 1d 011 000 00 00 100 01 000 1d
383
1d
01
dd
MODULE dcl TITLE 'Digital Combination Lock' X pin; "combination data input" R pin; "relock input" RESET pin; "asynchronous reset" CLOCK pin; Q2, Q1, Q0 pin istype 'reg'; LOCKED pin istype 'com'; "LOCKED indicator" UNLOCKED pin istype 'com'; "UNLOCKED indicator" ALARM pin istype 'com'; "ALARM indicator" QALL A0 A1 A2 A3 A4 A5 A6 A7 = = = = = = = = = [Q2,Q1,Q0]; [ 0, 0, 0]; [ 0, 0, 1]; [ 0, 1, 0]; [ 0, 1, 1]; [ 1, 0, 0]; [ 1, 0, 1]; [ 1, 1, 0]; [ 1, 1, 1]; state A3: if (R==1) then A0 else if (R==0)&(X==0) then A7 else if (R==0)&(X==1) then A4; if (R==1) then A0 else if (R==0)&(X==0) then A7 else if (R==0)&(X==1) then A5; if (R==1) then A0 else if (R==0)&(X==0) then A6 else if (R==0)&(X==1) then A7; if (R==1) then A0 (R==0) then A6;
state A4:
state A5:
state A6: else if state A7: goto A7; EQUATIONS QALL.CLK = CLOCK; QALL.AR = RESET; LOCKED = !Q2&!Q1&!Q0; UNLOCKED = Q2&Q1&!Q0; ALARM = Q2&Q1&Q0; END
STATE_DIAGRAM QALL state A0: if (R==1) then A0 else if (R==0)&(X==0) then A7 else if (R==0)&(X==1) then A1; if (R==1) then A0 else if (R==0)&(X==0) then A2 else if (R==0)&(X==1) then A7; if (R==1) then A0 else if (R==0)&(X==0) then A7 else if (R==0)&(X==1) then A3;
state A1:
state A2:
384
Summary
A sequencer recognizer is a state machine that produces output signal assertions in response to an input pattern Output signal assertions typically occur when the machine enters a final state associated with the accepting sequence Sequence recognizers are typically realized with Moore models, to prevent spurious behavior that might occur if the machines outputs could potentially change in response to an input signal change without clocking it
385