Snick  snack CPSC 121: Models of Computation 2010 Winter Term 2 Sequential Circuits (“Mealy Machines”) Steve Wolfman, based on notes by Patrice Belleville.

Slides:



Advertisements
Similar presentations
Snick  snack CPSC 121: Models of Computation 2009 Winter Term 1 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by Patrice.
Advertisements

1 Introduction Sequential circuit –Output depends not just on present inputs (as in combinational circuit), but on past sequence of inputs Stores bits,
Digital Design - Sequential Logic Design Chapter 3 - Sequential Logic Design.
Sequential Circuits1 DIGITAL LOGIC DESIGN by Dr. Fenghui Yao Tennessee State University Department of Computer Science Nashville, TN.
Circuits require memory to store intermediate data
Charles Kime & Thomas Kaminski © 2008 Pearson Education, Inc. (Hyperlinks are active in View Show mode) Chapter 5 – Sequential Circuits Part 1 – Storage.
CPSC 121: Models of Computation
Snick  snack CPSC 121: Models of Computation 2010 Winter Term 2 Introduction to Induction Steve Wolfman 1.
Snick  snack CPSC 121: Models of Computation 2009 Winter Term 1 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others.
Snick  snack CPSC 121: Models of Computation 2009 Winter Term 1 Introduction to Induction Steve Wolfman 1.
Snick  snack CPSC 121: Models of Computation 2009 Winter Term 1 DFAs in Depth Steve Wolfman, based on notes by Patrice Belleville and others.
Snick  snack A Working Computer Slides based on work by Bob Woodham and others.
Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Propositional Logic: Conditionals and Logical Equivalence Steve Wolfman, based on notes.
Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 Propositional Logic, Continued Steve Wolfman, based on notes by Patrice Belleville and.
1 Foundations of Software Design Lecture 3: How Computers Work Marti Hearst Fall 2002.
Snick  snack A Working Computer Slides based on work by Bob Woodham and others.
CS 300 – Lecture 3 Intro to Computer Architecture / Assembly Language Sequential Circuits.
Snick  snack CPSC 121: Models of Computation 2009 Winter Term 1 Sequential Circuits (“Mealy Machines”) Steve Wolfman, based on notes by Patrice Belleville.
Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others.
Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by.
Snick  snack CPSC 121: Models of Computation 2010 Winter Term 2 DFAs in Depth Benjamin Israel Notes heavily borrowed from Steve Wolfman’s,
Snick  snack CPSC 121: Models of Computation 2010 Winter Term 2 DFAs in Depth Steve Wolfman, based on notes by Patrice Belleville and others.
Snick  snack A Working Computer Slides based on work by Bob Woodham and others.
Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic, Continued Steve Wolfman, based on notes by Patrice Belleville.
10/22/2004EE 42 fall 2004 lecture 221 Lecture #22 Truth tables and gates This week: Circuits for digital devices.
Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Introduction & Motivation Steve Wolfman, based on notes by Patrice Belleville and others.
Some Useful Circuits Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University.
1 COMP541 State Machines Montek Singh Feb 8, 2012.
Quiz # 2 Chapters 4, 5, & 6.
Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 Building & Designing Sequential Circuits Steve Wolfman, based on notes by Patrice Belleville.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
1 Boolean Algebra & Logic Gates. 2 Objectives Understand the relationship between Boolean logic and digital computer circuits. Learn how to design simple.
Based on slides by Patrice Belleville and Steve Wolfman CPSC 121: Models of Computation Unit 8: Sequential Circuits.
Snick  snack CPSC 121: Models of Computation 2013W2 Introduction to Induction Steve Wolfman 1.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
Finite State Machines (FSMs) and RAMs and CPUs COS 116, Spring 2011 Sanjeev Arora.
Introduction to State Machine
Chapter 3 Digital Logic Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 3-2 Complete Example.
Snick  snack CPSC 121: Models of Computation 2011 Winter Term 1 Introduction to Induction Steve Wolfman 1.
Chapter 3 Digital Logic Structures. 3-2 Combinational vs. Sequential Combinational Circuit always gives the same output for a given set of inputs  ex:
CHAPTER-2 Fundamentals of Digital Logic. Digital Logic Digital electronic circuits are used to build computer hardware as well as other products (digital.
DLD Lecture 26 Finite State Machine Design Procedure.
MicroComputer Engineering DigitalCircuits slide 1 Combinational circuits Changes at inputs propagate at logic speed to outputs Not clocked No internal.
Registers; State Machines Analysis Section 7-1 Section 5-4.
CS/COE0447 Computer Organization & Assembly Language
1Sequential circuit design Acknowledgement: Most of the following slides are adapted from Prof. Kale's slides at UIUC, USA by Erol Sahin and Ruken Cakici.
CO5023 Latches, Flip-Flops and Decoders. Sequential Circuit What does this do? The OUTPUT of a sequential circuit is determined by the current output.
Instructor: Alexander Stoytchev CprE 281: Digital Logic.
1 COMP541 Finite State Machines - 1 Montek Singh Sep 22, 2014.
How does the CPU work? CPU’s program counter (PC) register has address i of the first instruction Control circuits “fetch” the contents of the location.
CSE 140: Components and Design Techniques for Digital Systems Lecture 7: Sequential Networks CK Cheng Dept. of Computer Science and Engineering University.
COMBINATIONAL AND SEQUENTIAL CIRCUITS Guided By: Prof. P. B. Swadas Prepared By: BIRLA VISHVAKARMA MAHAVDYALAYA.
Chapter 3 Boolean Algebra and Digital Logic T103: Computer architecture, logic and information processing.
Mealy and Moore Machines Lecture 8 Overview Moore Machines Mealy Machines Sequential Circuits.
1 COMP541 Sequential Logic – 2: Finite State Machines Montek Singh Feb 29, 2016.
CPSC 121: Models of Computation 2008/9 Winter Term 2
Digital Design - Sequential Logic Design
Basics of Logic gates - Part 2
CPSC 121: Models of Computation 2016W2
COMP541 Sequential Logic – 2: Finite State Machines
How does the CPU work? CPU’s program counter (PC) register has address i of the first instruction Control circuits “fetch” the contents of the location.
Theory of Computation Turing Machines.
CSE 370 – Winter Sequential Logic - 1
CSE 370 – Winter Sequential Logic-2 - 1
Branch instructions We’ll implement branch instructions for the eight different conditions shown here. Bits 11-9 of the opcode field will indicate the.
Control units In the last lecture, we introduced the basic structure of a control unit, and translated our assembly instructions into a binary representation.
Flip-Flops.
CPSC 121: Models of Computation
CPSC 121: Models of Computation 2008/9 Winter Term 2
CPSC 121: Models of Computation
Presentation transcript:

snick  snack CPSC 121: Models of Computation 2010 Winter Term 2 Sequential Circuits (“Mealy Machines”) Steve Wolfman, based on notes by Patrice Belleville and others 1

Outline Prereqs, Learning Goals, and Quiz Notes Problems and Discussion –A Pushbutton Light Switch –Memory and Events: D Latches & Flip-Flops –General Implementation of DFAs (with a more complex DFA as an example) –How Powerful are DFAs? Next Lecture Notes 2

Learning Goals: Pre-Class We are mostly departing from the readings for next class to talk about a new kind of circuit on our way to a full computer: sequential circuits. The pre-class goals are to be able to: –Trace the operation of a deterministic finite-state automaton (represented as a diagram) on an input, including indicating whether the DFA accepts or rejects the input. –Deduce the language accepted by a simple DFA after working through multiple example inputs. 3

Learning Goals: In-Class 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. 4

Where We Are in The Big Stories Theory How do we model computational systems? Now: With our powerful modelling language (pred logic), we can prove things like universality of NAND gates for combinational circuits. Our new model (DFAs) are sort of full computers. Hardware How do we build devices to compute? Now: Learning to build a new kind of circuit with memory that will be the key new feature we need to build full- blown computers! 5

Outline Prereqs, Learning Goals, and Quiz Notes Problems and Discussion –A Pushbutton Light Switch –Memory and Events: D Latches & Flip-Flops –General Implementation of DFAs (with a more complex DFA as an example) –How Powerful are DFAs? Next Lecture Notes 6

Problem: Toggle Light Switch Problem: Design a circuit to control a light so that the light changes state any time its “push-button” switch is pressed. (Like the light switches in Dempster: Press and release, and the light changes state. Press and release again, and it changes again.) ? ? 7

Concept Q: Toggle Switch How many gates does the circuit take? a.One b.Two c.Three d.None of these (b/c it’s a different number) e.None of these (b/c it can’t be done) ? ? 8

A Light Switch “DFA” light off light on toggle This Deterministic Finite Automaton (DFA) isn’t really about accepting/rejecting; its current state is the state of the light. ? ? 9

Outline Prereqs, Learning Goals, and !Quiz Notes Problems and Discussion –A Pushbutton Light Switch –Memory and Events: D Latches & Flip-Flops –General Implementation of DFAs (with a more complex DFA as an example) –How Powerful are DFAs? Next Lecture Notes 10

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. 11

Worked Problem: “Muxy Memory” Worked Problem: How can we use a mux to store a bit of memory? Let’s have it output the stored bit when the control is 0 and load a new value when the control is output ??? new data control 12

Worked Problem: Muxy Memory Worked Problem: How can we use a mux to store a bit of memory? Let’s have it output the stored bit when the control is 0 and load a new value when the control is output (Q) old output (Q’) new data (D) control (G) This violates our basic combinational constraint: no cycles. 13

Problem: Truth Table for Muxy Memory (AKA D Latch) Problem: Write a truth table for the D Latch. GDQ'Q

Truth Table for D Latch Fill in the D latch’s truth table: GDQ' a.b.c.d.e. Q Q Q F F 1 Q None of these 15

Worked Problem: Truth Table for D Latch Worked Problem: Write a truth table for the D Latch. GDQ'Q Like a “normal” mux table, but what happens when Q'  Q? 16

Worked Problem: Truth Table for D Latch Worked Problem: Write a truth table for the D Latch. GDQ'Q Q' “takes on” Q’s value at the “next step”. 17

D Latch Symbol + Semantics When G is low, the latch maintains its memory. When G is high, the latch loads a new value from D. 0 1 output (Q) old output (Q’) new data (D) control (G) 18

D Latch Symbol + Semantics When G is low, the latch maintains its memory. When G is high, the latch loads a new value from D. 0 1 output (Q) old output (Q’) new data (D) control (G) 19

D Latch Symbol + Semantics When G is low, the latch maintains its memory. When G is high, the latch loads a new value from D. output (Q) new data (D) control (G) D G Q 20

Hold On!! Why does the D Latch have two inputs and one output when the mux inside has THREE inputs and one output? a.The D Latch is broken as is; it should have three inputs. b.A circuit can always ignore one of its inputs. c.One of the inputs is always true. d.One of the inputs is always false. e.None of these (but the D Latch is not broken as is). 21

Using the D Latch for Circuits with Memory Problem: What goes in the cloud? What do we send into G? D G Q Combinational Circuit to calculate next state inputoutput ?? 22

Using the D Latch for Our Light Switch Problem: What do we send into G? D G Q inputoutput ?? current light state a.T if the button is down, F if it’s up. b.T if the button is up, F if it’s down. c.Neither of these. 23

A Timing Problem: We Need EVENTS! Problem: What do we send into G? D G Q output “pulse” when button is pressed current light state button pressed As long as the button is down, D flows to Q flows through the NOT gate and back to D... which is bad! 24

A Timing Problem, Metaphor (from MIT 6.004, Fall 2002) What’s wrong with this tollbooth? P.S. Call this a “bar”, not a “gate”, or we’ll tie ourselves in (k)nots. 25

A Timing Solution, Metaphor (from MIT 6.004, Fall 2002) Is this one OK? 26

A Timing Problem Problem: What do we send into G? D G Q output “pulse” when button is pressed current light state button pressed As long as the button is down, D flows to Q flows through the NOT gate and back to D... which is bad! 27

A Timing Solution (Almost) D G Q output button pressed D G Q Never raise both “bars” at the same time. 28

A Timing Solution D G Q output D G Q ?? 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). 29

A Timing Solution D G Q output D G Q button pressed button press signal 30

Master/Slave D Flip-Flop Symbol + Semantics When CLK goes from low to high, the flip-flop loads a new value from D. Otherwise, it maintains its current value. output (Q) new data (D) control or “clock” signal (CLK) D G Q D G Q 31

Master/Slave D Flip-Flop Symbol + Semantics When CLK goes from low to high, the flip-flop loads a new value from D. Otherwise, it maintains its current value. output (Q) new data (D) control or “clock” signal (CLK) D G Q D G Q 32

Master/Slave D Flip-Flop Symbol + Semantics When CLK goes from low to high, the flip-flop loads a new value from D. Otherwise, it maintains its current value. output (Q) new data (D) control or “clock” signal (CLK) D G Q D G Q 33

Master/Slave D Flip-Flop Symbol + Semantics When CLK goes from low to high, the flip-flop loads a new value from D. Otherwise, it maintains its current value. new data clock signal D Q output 34

A Pushbutton Light Switch output button press signal D Q What goes here? a.A wirec. An AND gatee. None of these. b.A NOT gated. An XOR gate 35

Outline Prereqs, Learning Goals, and !Quiz Notes Problems and Discussion –A Pushbutton Light Switch –Memory and Events: D Latches & Flip-Flops –General Implementation of DFAs (with a more complex DFA as an example) –How Powerful are DFAs? Next Lecture Notes 36

“Mealy Machines”  DFAs whose state matters A “Mealy Machine” is a DFA that’s not about accepting or rejecting but about outputting values as it transitions. Its output can depend on its state and its input. Let’s work with a specific example... 37

Branch Prediction Machine Modern computers “pre-execute” instructions... but to pre-execute an “if” (AKA branch), they have to guess whether to execute the then or else part. Here’s one reasonable way to guess: whatever the last branch did, the next one will, too. (Why? Think loops!) It’s nice to build some “inertia” into this so it won’t flip its guess at the first failure... 38

Implementing the Branch Predictor Here’s that algorithm as a DFA (with no accepting state): Can we build a branch prediction circuit? YES! yes? no? NO! not taken taken not taken taken not taken taken not taken 39

General Implementation of DFAs as “Mealy Machines” Each time the clock “ticks” move from one state to the next. D Q Combinational circuit to calculate next state/output inputoutput CLK Each of these lines (except the clock) may carry multiple bits; the D flip-flop may be several flip-flops to store several bits. 40

How to Implement a DFA as a “Mealy Machine” (1)Number the states, starting with 0, and figure out how many bits you need 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)Lay out enough D flip-flops to store the state. (4)For each state, build a combinational circuit that determines the next state and the output given the input. (A separate circuit for each state! These are often very simple!) (5)Send all those “next states” and outputs from the circuits into multiplexers, and use the current state as the control signal. (So, only the appropriate circuit from (4) gets used.) (6)Send the multiplexer output back into your flip-flops. 41

Implementing the Predictor Step YES! 3 yes? 2 no? 1 NO! 0 not taken taken not taken taken not taken taken not taken How many 1-bit flip-flops do we need to represent the state? a.0 (no memory is needed) b.1 c.2 d.3 e.None of these taken = 1 not taken = 0 42

Just Truth Tables... Current StatetakenNew state YES! 3 yes? 2 no? 1 NO! 0 not taken taken not taken taken not taken taken not taken What’s in this row? a.0 0 b.0 1 c.1 0 d.1 1 e.None of these. 43

Just Truth Tables... Current StatetakenNew state YES! 3 yes? 2 no? 1 NO! 0 not taken taken not taken taken not taken taken not taken 44

Renaming to Make a Pattern Clearer... predlasttakenpred'last' YES! 3 yes? 2 no? 1 NO! 0 not taken taken not taken taken not taken taken not taken 45

Implementing the Predictor: Step 3 We always use this pattern. In this case, we need two flip-flops. D Q Combinational circuit to calculate next state/output inputoutput CLK D Q Let’s switch to TkGate schematics... 46

??? Implementing the Predictor: Step 3 D Q ?? input output CLK D Q 47

Implementing the Predictor: Step 3 48 ???

Implementing the Predictor: Step

Implementing the Predictor: Step What should the next “prediction” be in state 0? a.same value as “taken” switch b.negation of “taken” switch (“~taken”) c.T d.F e.None of these. 50

Implementing the Predictor: Step What should the next prediction be in state 1? a.taken b.~taken c.T d.F e.None of these. 51

Implementing the Predictor: Step What should the next prediction be in state 2? a.taken b.~taken c.T d.F e.None of these. 52

Implementing the Predictor: Step What should the next prediction be in state 3? a.taken b.~taken c.T d.F e.None of these. 53

Just Truth Tables... predlasttakenpred'last'

Implementing the Predictor: Step

Implementing the Predictor: Step What should the next “last” value be in state 0? a.taken b.~taken c.T d.F e.None of these. 56

Implementing the Predictor: Step TADA!! 57

You can often simplify, but that’s not the point. 58

Outline Prereqs, Learning Goals, and !Quiz Notes Problems and Discussion –A Pushbutton Light Switch –Memory and Events: D Latches & Flip-Flops –General Implementation of DFAs (with a more complex DFA as an example) –How Powerful are DFAs? Next Lecture Notes 59

Steps to Build a Powerful Machine (1)Number the states, starting with 0, and figure out how many bits you need 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)Lay out enough D flip-flops to store the state. (4)For each state, build a combinational circuit that determines the next state and the output given the input. (A separate circuit for each state!) (5)Send all those “next states” and outputs from the circuits into multiplexers, and use the current state as the control signal. (6)Send the multiplexer output back into your flip-flops. 60

How Powerful Is a DFA? How does a DFA compare to a modern computer? a.Modern computer is more powerful. b.DFA is more powerful. c.They’re the same. 61

Where We’ll Go From Here... We’ll come back to DFAs again later in lecture. In two upcoming labs, you’ll: Build a circuit to perform a practical task using techniques like these. Explore how to build something like a DFA that can run other DFAs... a general purpose computer. 62

Outline Prereqs, Learning Goals, and !Quiz Notes Problems and Discussion –A Pushbutton Light Switch –Memory and Events: D Latches & Flip-Flops –General Implementation of DFAs (with a more complex DFA as an example) –How Powerful are DFAs? Next Lecture Notes 63

Learning Goals: In-Class 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. 64

Next Lecture Learning Goals: Pre-Class By the start of class, you should be able to: –Convert sequences to and from explicit formulas that describe the sequence. –Convert sums to and from summation/”sigma” notation. –Convert products to and from product/”pi” notation. –Manipulate formulas in summation/product notation by adjusting their bounds, merging or splitting summations/products, and factoring out values. 65

Next Lecture Prerequisites See the Mathematical Induction Textbook Sections at the bottom of the “Textbook and References” page.Mathematical Induction Textbook Sections Complete the open-book, untimed quiz on Vista that’s due before the next class. 66

snick  snack More problems to solve... (on your own or if we have time) 67

Problem: Traffic Light Problem: Design a DFA with outputs to control a set of traffic lights. 68

Problem: Traffic Light Problem: Design a DFA with outputs to control a set of traffic lights. Thought: try allowing an output that sets a timer which in turn causes an input like our toggle when it goes off. Variants to try: - Pedestrian cross-walks - Turn signals - Inductive sensors to indicate presence of cars - Left-turn signals 69

1 23 aa a,b,c b b,c c PROBLEM: Does this accept the empty string? 70