Based on slides by Patrice Belleville and Steve Wolfman
CPSC 121: Models of Computation Unit 8: Sequential Circuits Based - - PowerPoint PPT Presentation
CPSC 121: Models of Computation Unit 8: Sequential Circuits Based - - PowerPoint PPT Presentation
CPSC 121: Models of Computation Unit 8: Sequential Circuits Based on slides by Patrice Belleville and Steve Wolfman Announcements Pre-class quiz #9 is due Wednesday November 8th at 9:00 pm. Textbook sections: o Epp, 4th edition: 5.1 to
Announcements
Pre-class quiz #9 is due Wednesday November 8th at
9:00 pm.
- Textbook sections:
- Epp, 4th edition: 5.1 to 5.4
- Epp, 3rd edition: 4.1 to 4.4
- Rosen, 6th edition: 4.1, 4.2
- Rosen, 7th edition: 5.1, 5.2
Assignment #4 is due Friday November 10th at 4:00
pm.
Unit 8 - Sequential Circuits 2
Announcements (cont')
Midterm #2:
- Wednesday November 15th 6:00-7:00 pm.
- Locations:
- Section 101: HEBB 100
- Sections 102 and 103 : CIRS 1250
- It will focus on
- Slides: Units 5 to 8
- The pre-class readings for quizzes 5 to 8
- Labs 5 to 8.
- You will be given a copy of Dave’s Excellent Formula Sheet
- You can bring one 8.5 x 11in (21.59 x 27.94cm) two sided sheet
- f paper.
- No textbook, calculator or other electronic equipment is allowed.
- Please email the course coordinator by Nov 8 if you have a
conflict.
Unit 8 - Sequential Circuits 3
Announcements (cont')
Pre-class quiz #10 is tentatively due Monday November
20th at 19:00.
- Textbook sections:
- Epp, 4th edition: 6.1, 7.1
- Epp, 3rd edition: 5.1, 6.1
- Rosen, 6th edition: 2.1, 2.3 up to the top of page 136.
- Rosen, 7th edition: 2.1, 2.3 down to the bottom of page
141.
Unit 8 - Sequential Circuits 4
Pre-Class Learning Goals
By the start of class, you should be able to
- Trace the operation of a DFA (deterministic finite-
state automaton) represented as a diagram on an input, and indicate whether the DFA accepts or rejects the input.
- Deduce the language accepted by a simple DFA
after working through multiple example inputs.
Unit 8 - Sequential Circuits 5
Quiz 8 feedback:
Over all: Issues : Push-button light question:
- We will revisit this problem soon.
Unit 8 - Sequential Circuits 6
In-Class Learning Goals
By the end of this unit, you should be able to:
- Translate a DFA into a sequential circuit that
implements the DFA.
- Explain how and why each part of the resulting
circuit works.
Unit 8 - Sequential Circuits 7
Related to CPSC 121 Big Questions
How can we build a computer that is able to
execute a user-defined program?
- Computers execute instructions one at a time.
- They need to remember values, unlike the circuits you
designed in labs 1, 2, 3 and 4.
NOW: We are learning to build a new kind of
circuits with memory that will be the key new feature we need to build full-blown computers!
Unit 8 - Sequential Circuits 8
? ?
Unit Outline
Sequential Circuits :Latches, and flip-flops. DFA Example Implementing DFAs Other problems and exercises.
Unit 8 - Sequential Circuits 9
Problem: Light Switch
Problem:
- Design a circuit to control a light so that the light changes
state any time its “push-button” switch is pressed.
Unit 8 - Sequential Circuits 10
?
DFA for Push-Button Switch
This Deterministic Finite Automaton (DFA) isn’t really
about accepting/rejecting; its current state is the state
- f the light.
A circuit that implements a DFA needs to remember
the current state:
- It needs memory.
11
?
light
- ff
pressed pressed
light
- n
Unit 8 - Sequential Circuits
Departures from Combinational Circuits
MEMORY:
We need to “remember” the light’s state.
EVENTS:
We need to act on a button push rather than in response to an input value.
12 Unit 8 - Sequential Circuits
How Do We Remember?
We want a circuit that:
- Sometimes… remembers its current state.
- Other times… loads a new state and remembers it.
Sounds like a choice. What circuit element do we have for modelling
choices?
13 Unit 8 - Sequential Circuits
“Mux Memory”
How do we use a mux to store a bit of memory? We choose to remember the old value on a control
value of 0 and to load a new value on a 1.
14
What should Mux's input 0 be?
1
- utput
??? new data control
Unit 8 - Sequential Circuits
“Mux Memory”
So, our circuit will look like the following:
15
This violates our basic combinational constraint: no cycles.
1
- utput (Q)
new data (D) control (G)
- ld output (Q’)
Unit 8 - Sequential Circuits
Truth Table for “Mux Memory”
Fill in the MM’s truth table:
G D Q' 1 1 1 1 1 1 1 1 1 1 1 1
a. b. c. d. e.
Q 1 1 1 1 Q 1 1 1 1 Q 1 1 X X 1 Q 1 1 1 1
None
- f
these
16 Unit 8 - Sequential Circuits
Truth Table for “Mux Memory”
The truth table for the MM:
G D Q' Q 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Like a “normal” mux table, but what happens when Q' Q?
17 Unit 8 - Sequential Circuits
Truth Table for “Muxy Memory”
The truth table for the MM:
G D Q' Q 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Q' “takes on” Q’s value at the “next step”.
18 Unit 8 - Sequential Circuits
D Latches
We call a "mux-memory" a D-latch ( recall from lab #5)
- When G is 0, the latch retains its current value.
- When G is 1, the latch loads a new value from D.
Unit 8 - Sequential Circuits 19
1
- utput (Q)
- ld output (Q’)
new data (D) control (G)
D Latch (as a component)
When G is 0, the latch maintains its memory. When G is 1, the latch loads a new value from D.
- utput (Q)
new data (D) control (G)
20
D Q G
Unit 8 - Sequential Circuits
Back to the Light Switch Problem
Problem:
- Design a circuit to control a light so that the light changes
state any time its “push-button” switch is pressed.
Let's use a D-Latch to implement our circuit.
Unit 8 - Sequential Circuits 21
?
Push-Button Switch
What signal does the button generate?
Unit 8 - Sequential Circuits 22
low high
Using a D Latch for Our Light Switch
What goes in the cloud? What do we send into G?
Combinational Circuit to calculate next state
input ??
23
D G Q
- utput
Unit 8 - Sequential Circuits
Using the D Latch for Our Light Switch
Problem: What do we send into G?
- a. 1 if the button is down, 0 if it’s up.
- b. 1 if the button is up, 0 if it’s down.
- c. Neither of these.
24
D G Q
- utput
?? current light state
Unit 8 - Sequential Circuits
Using the D Latch for Our Light Switch
Problem: What should be the next state of the light?
25
D G Q
- utput
current light state “pulse” when button is pressed button pressed
Unit 8 - Sequential Circuits
Using a D Latch for Our Light Switch
Will this work?
26
D G Q
- utput
current light state “pulse” when button is pressed button pressed
Unit 8 - Sequential Circuits
Push-Button Switch
What is wrong with our solution?
A. We should have used XOR instead of NOT. B. As long as the button is down, D flows to Q, and it flows through the NOT gate and back to D and so on...which is bad!
- C. The delay introduced by the NOT gate is too long.
- D. As long as the button is down, Q flows to D, and it flows back
to Q... and Q (the output) does not change!
- E. There is some other problem with the circuit.
Unit 8 - Sequential Circuits 27
A Timing Problem
This toll booth has a similar problem. What is wrong with this booth?
Unit 8 - Sequential Circuits 28
From MIT 6.004, Fall 2002
P.S. Call this a “bar”, not a “gate”, or we'll tie ourselves in (k)nots.
A Timing Solution
Can 2 bars (set like in the picture)
solve the problem ?
Unit 8 - Sequential Circuits 29
From MIT 6.004, Fall 2002
Our Timing Problem
As long as the button is down, D flows to Q flows
through the NOT gate and back to D and so on... which is bad!
We need a second "bar".
30
“pulse” when button is pressed D G Q
- utput
current light state
Unit 8 - Sequential Circuits
A Timing Solution (Almost)
31
D G Q
- utput
D G Q Problem: We should never raise both “bars” at the same time.
Can this work?
Unit 8 - Sequential Circuits
A Timing Solution
The two latches are never enabled at the same time (except for the moment needed for the NOT gate on the left to compute, which is so short that no “cars” get through).
32
D G Q
- utput
D G Q button press signal
Let's trace it :
Unit 8 - Sequential Circuits
Button is LO (unpressed)
LO
33
We’re assuming the circuit has been set up and is “running normally”. Right now, the light is off (i.e., the output of the right latch is 0).
D G Q
- utput
D G Q 1 1 1
Unit 8 - Sequential Circuits
Button goes HI (is pressed)
34
This stuff is processing a new signal. D G Q
- utput
D G Q HI 1 1 1 1
Unit 8 - Sequential Circuits
Propagating signal.. left NOT, right latch
35
This stuff is processing a new signal. D G Q
- utput
D G Q HI 1 1 1 1
Unit 8 - Sequential Circuits
Propagating signal.. right NOT (steady state)
36
Why doesn’t the left latch update?
- a. Its D input is 0.
- b. Its G input is 0.
- c. Its Q output is 1.
- d. It should update!
D G Q
- utput
D G Q HI 1 1 1
Unit 8 - Sequential Circuits
Button goes LO (released)
37
This stuff is processing a new signal. D G Q
- utput
LO 1 1 D G Q
Unit 8 - Sequential Circuits
Propagating signal.. left NOT
38
This stuff is processing a new signal. D G Q
- utput
D G Q LO 1 1 1
Unit 8 - Sequential Circuits
Propagating signal.. left latch (steady state)
39
And, we’re done with one cycle. D G Q
- utput
D G Q LO 1 1
Unit 8 - Sequential Circuits
Master/Slave D Flip-Flop
When CLK goes from 0 (low) to 1 (high), the flip-flop loads a new value from D. Otherwise, it maintains its current value.
40
- utput
(Q) new data (D) control
- r
“clock” signal (CLK) D G Q D G Q
Unit 8 - Sequential Circuits
Master/Slave D Flip-Flop
When CLK goes from 0 (low) to 1 (high), the flip-flop loads a new value from D. Otherwise, it maintains its current value.
41
- utput
(Q) new data (D) control
- r
“clock” signal (CLK) D G Q D G Q
Unit 8 - Sequential Circuits
Master/Slave D Flip-Flop
When CLK goes from 0 (low) to 1 (high), the flip-flop loads
a new value from D.
Otherwise, it maintains its current value.
42
We rearranged the clock and D inputs and the output to match Logisim.
new data clock signal D Q
- utput
Unit 8 - Sequential Circuits
Push-Button Switch: Solution
Using a D- flip-flop
Unit 8 - Sequential Circuits 43
Unit Outline
Sequential Circuits :Latches, and flip-flops. DFA Example Implementing DFAs Other problems and exercises.
Unit 8 - Sequential Circuits 44
Finite-State Automata
There are two types of Finite-State Automata:
Those whose output is determined solely by the final
state (Moore machines).
- Used to match a string to a pattern.
- Input validation.
- Searching text for contents.
- Lexical Analysis: the first step in a compiler or an
interpreter.
- (define (fun x) (if (<= x 0) 1 (* x (fun (- x 1)))))
Unit 8 - Sequential Circuits 45
( define ( fun x ) ( if ( <= x 0 ) 1 ( * x ( fun ( - x 1 ) ) ) ) )
Finite-State Automata
Those that produce output every time the state
changes (Mealy machines).
- Examples:
- Simple ciphers
- Traffic lights controller.
- etc.
A circuit that implements a finite state machine of
either type needs to remember the current state:
- It needs memory.
Unit 8 - Sequential Circuits 46
DFA Example
Suppose we want to design a Finite State Automaton
with input alphabet {a, b} that accepts the sets of all strings that contain exactly two b's. How many states will the DFA have?
A. 2 B. 4
- C. 8
- D. Another value less than 8.
E. Another value larger than 8.
Unit 8 - Sequential Circuits 47
The DFA
Unit 8 - Sequential Circuits 48
Can you check that it is correct? Can we design a circuit for it?
Unit Outline
Latches, toggles and flip-flops. DFA Example Implementing DFAs Other problems and exercises.
Unit 8 - Sequential Circuits 49
Implementing a DFA
(1) Number the states, starting with 0, and figure out how
many bits you needed to store the state number.
(2) Number the inputs, starting with 0, and figure out how
many bits you need to represent the input.
(3) Layout enough D flip-flops to store the state (one per bit). (4)
For each state, build a combinational circuit that computes the next state (and the output if needed) given the input. (Use a separate circuit for each state, they are
- ften very simple!)
(5) Send the next states into a MUX with the current state as
the control signal (only the appropriate next state gets used)!
(6) Store the next state (i.e. MUX’s output) back into the D
flip-flops.
Unit 8 - Sequential Circuits 50
Implementing the example: Step 1&2
How many bits (and 1-bit flip-flops) we need to represent the states? a. 0, no memory needed b. 1 c. 2 d. 3 e. None of these
As always, we use numbers to represent the inputs: a = 0 b = 1
51
Unit 8 - Sequential Circuits
Modelling the transitions …
Current State input New state 1 1 1 1 1 1 1 1 1 1 1 1 1
What’s in this row? a. 0 0 b. 0 1 c. 1 0 d. 1 1 e. None of these.
52
Reminder: a = 0 b = 1
Use just truth tables:
Unit 8 - Sequential Circuits
Modelling the transitions …
Current State input New state 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
53
Reminder: a = 0 b = 1 The table below describes the complete behaviour of the DFA:
Unit 8 - Sequential Circuits
Template for a DFA Circuit
We always use this pattern. In this case, we need two flip-flops.
Unit 8 - Sequential Circuits 54
Compute Output Next State circuits
Implementing the example: Step 3, part of 4 and step 5
We switch to Logisim :
55
Unit 8 - Sequential Circuits
Implementing the example: Step 3, part of 4 and step 5
Adding the output :
56
Unit 8 - Sequential Circuits
Implementing step 4
We will now implement the
combinational circuit that computes the next state from state 0 :
Unit 8 - Sequential Circuits
57
What should be the value of Bit 0 of the next state from state 0? Hint: look at the DFA, not at the circuit! a. input b. ~input c. 1 d. e. None of these.
Bit 1 Bit 0 input Bit 1 Bit 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Current state Next state
Implementing step 4
Therefore, here is a
combinational circuit that computes the next state from state 0:
Let's build the circuits for the rest of the states in
Logisim.
Unit 8 - Sequential Circuits
58
Bit 1 Bit 0 input Bit 1 Bit 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Current state Next state
Where We’ll Go From Here...
We’ll come back to DFAs again later in the lectures. In the labs you have been and will continue to explore
what you can do once you have memory and events.
And, before long, how you combine these into a
working computer!
In the labs, you’ll also work with a widely used
representation equivalent to DFAs: regular expressions.
59 Unit 8 - Sequential Circuits
Unit Outline
Sequential Circuits :Latches, and flip-flops. DFA Example Implementing DFAs Other problems and exercises.
Unit 8 - Sequential Circuits 60
Exercises
Real numbers:
- We can write numbers in decimal using the format
(-)? d+ (.d+)?
- where the ( )? mean that the part in parentheses is optional,
and d+ stands for “1 or more digits”.
- Design a DFA that will accept input strings that are valid real
numbers using this format.
- You can use else as a label on an edge instead of listing
every character that does not appear on another edge leaving from a state.
Unit 8 - Sequential Circuits 61
Exercises
Real numbers (continued)
- Then design a circuit that turns a LED on if the input is
a valid real number, and off otherwise.
- Hint: Logisim has a keyboard component you can
use.
- Hint: our DFA for this problem has 6 states.
Design a DFA for a vending machine that sells one of
three items (lemon juice, whiteboard markers, and potato chips) for 35¢ each. It should accept 5¢, 10¢ and 25¢ coins, and does not need to return change.
Unit 8 - Sequential Circuits 62