State & Finite State Machines Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H Appendix C.7. C.8, C.10, C.11.

Slides:



Advertisements
Similar presentations
Lab 2: Finite State Machines CS 3410 Spring 2015.
Advertisements

Finite State Machines (FSMs)
Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University See P&H Appendix B.7. B.8, B.10, B.11.
Changes in input values are reflected immediately (subject to the speed of light and electrical delays) on the outputs Each gate has an associated “electrical.
CS 151 Digital Systems Design Lecture 19 Sequential Circuits: Latches.
Classification of Digital Circuits  Combinational. Output depends only on current input values.  Sequential. Output depends on current input values and.
Multiplexors Sequential Circuits and Finite State Machines Prof. Sin-Min Lee Department of Computer Science.
Digital Logic Circuits (Part 2) Computer Architecture Computer Architecture.
Circuits require memory to store intermediate data
Dr. ClincyLecture1 Appendix A – Part 2: Logic Circuits Current State or output of the device is affected by the previous states Circuit Flip Flops New.
State and Finite State Machines
Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University See P&H Appendix B.7. B.8, B.10, B.11.
Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University See P&H Appendix B.7. B.8, B.10, B.11.
Arithmetic Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H 2.4 (signed), 2.5, 2.6, C.6, and Appendix C.6.
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University State & Finite State Machines See: P&H Appendix C.7. C.8, C.10, C.11.
Hakim Weatherspoon CS 3410, Spring 2011 Computer Science Cornell University Memory See: P&H Appendix C.8, C.9.
ENGIN112 L20: Sequential Circuits: Flip flops October 20, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 20 Sequential Circuits: Flip.
Give qualifications of instructors: DAP
CS 151 Digital Systems Design Lecture 20 Sequential Circuits: Flip flops.
State & Finite State Machines Hakim Weatherspoon CS 3410, Spring 2011 Computer Science Cornell University See P&H Appendix C.7. C.8, C.10, C.11.
1 Chapter 5: Datapath and Control CS 447 Jason Bakos.
SEQUENTIAL CIRCUITS Introduction
Flip-flops, Latches and State Prof. Sirer COMP 303 Koç University.
Sequential Logic Materials taken from: Digital Design and Computer Architecture by David and Sarah Harris & The Essentials of Computer Organization and.
Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University Memory See: P&H Appendix C.8, C.9.
Memory Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University.
Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University Memory See: P&H Appendix C.8, C.9.
Memory Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University.
1 CSE370, Lecture 17 Lecture 17 u Logistics n Lab 7 this week n HW6 is due Friday n Office Hours íMine: Friday 10:00-11:00 as usual íSara: Thursday 2:30-3:20.
Sequential Logic Combinatorial components: the output values are computed only from their present input values. Sequential components: their output values.
Computer Organization & Programming Chapter 5 Synchronous Components.
CS 352 : Computer Organization and Design University of Wisconsin-Eau Claire Dan Ernst Latches & Flip-Flops.
1 CSE370, Lecture 18 Lecture 20 u Logistics n HW6 due Wednesday n Lab 7 this week (Tuesday exception) n Midterm 2 Friday (covers material up to simple.
Chapter 6 – Digital Electronics – Part 1 1.D (Data) Flip Flops 2.RS (Set-Reset) Flip Flops 3.T Flip Flops 4.JK Flip Flops 5.JKMS Flip Flops Information.
Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University See P&H Appendix B.8 (register files) and B.9.
Synchronous Sequential Circuits by Dr. Amin Danial Asham.
Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University See P&H Appendix B.7. B.8, B.10, B.11.
CS151 Introduction to Digital Design Chapter 5: Sequential Circuits 5-1 : Sequential Circuit Definition 5-2: Latches 1Created by: Ms.Amany AlSaleh.
Synchronous Sequential Circuits by Dr. Amin Danial Asham.
Presentation on Digital Door Lock Digital System Design Presenter: Subash Chandra Pakhrin 072MSI616 MSC in Information and Comm. Engineering Pulchowk Campus.
Digital Design - Sequential Logic Design
Dr. Clincy Professor of CS
Chapter #6: Sequential Logic Design
Clocks A clock is a free-running signal with a cycle time.
Computer Architecture & Operations I
State & Finite State Machines
Lecture 8 Dr. Nermi Hamza.
Digital Design Lecture 9
Dr. Clincy Professor of CS
Asynchronous Inputs of a Flip-Flop
Assistant Prof. Fareena Saqib Florida Institute of Technology
ECE Digital logic Lecture 16: Synchronous Sequential Logic
Latches and Flip-flops
Sequential logic circuits
CS Fall 2005 – Lec. #5 – Sequential Logic - 1
Hakim Weatherspoon CS 3410 Computer Science Cornell University
Computer Science 210 Computer Organization
Hakim Weatherspoon CS 3410 Computer Science Cornell University
Dr. Clincy Professor of CS
CSE 370 – Winter Sequential Logic - 1
Dr. Clincy Professor of CS
Lecture 17 Logistics Last lecture Today HW5 due on Wednesday
Lecture 20 Logistics Last lecture Today HW6 due Wednesday
Lecture 17 Logistics Last lecture Today HW5 due on Wednesday
Lecture 22 Logistics Last lecture Today HW7 is due on Friday
SEQUENTIAL CIRCUITS __________________________________________________
Lecture 22 Logistics Last lecture Today HW7 is due on Friday
Hakim Weatherspoon CS 3410 Computer Science Cornell University
Instructor: Michael Greenbaum
Clocks A clock is a free-running signal with a cycle time.
Presentation transcript:

State & Finite State Machines Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H Appendix C.7. C.8, C.10, C.11

2 Stateful Components Until now is combinatorial logic Output is computed when inputs are present System has no internal state Nothing computed in the present can depend on what happened in the past! Need a way to record data Need a way to build stateful circuits Need a state-holding device Finite State Machines Inputs Combinational circuit Outputs N M

3 Unstable Devices B A C

Bistable Devices In stable state, A = B How do we change the state? A B A B 1 A B A Simple Device Stable and unstable equilibria?

SR Latch Set-Reset (S-R) Latch Stores a value Q and its complement S R Q Q SRQQ

SR Latch Set-Reset (S-R) Latch Stores a value Q and its complement S=1 and R=1 ? S R Q Q SRQQ

SR Latch Set-Reset (S-R) Latch Stores a value Q and its complement S=1 and R=1 ? S R Q Q SRQQ 00QQ ?? S R Q Q

(Unclocked) D Latch Data (D) Latch –Easier to use than an SR latch –No possibility of entering an undefined state When D changes, Q changes  … immediately (…after a delay of 2 Ors and 2 NOTs) Need to control when the output changes D S R Q Q S R Q Q D DQQ 0 1

(Unclocked) D Latch Data (D) Latch –Easier to use than an SR latch –No possibility of entering an undefined state When D changes, Q changes  … immediately (…after a delay of 2 Ors and 2 NOTs) Need to control when the output changes D S R Q Q S R Q Q D DQQ

Clocks Clock helps coordinate state changes –Usually generated by an oscillating crystal –Fixed period; frequency = 1/period 1 0

Edge-triggering Can design circuits to change on the rising or falling edge Trigger on rising edge = positive edge-triggered Trigger on falling edge = negative edge-triggered Inputs must be stable just before the triggering edge input clock

Clock Disciplines Level sensitive –State changes when clock is high (or low) Edge triggered –State changes at clock edge positive edge-triggered negative edge-triggered

13 Clock Methodology Negative edge, synchronous –Signals must be stable near falling clock edge Positive edge synchronous Asynchronous, multiple clocks,... clk computesave t setup t hold computesavecompute t combinational

14 D Latch with Clock S R D clk Q Q SRQQ 00 QQ forbidden clkDQQ 00 QQ 01 QQ

15 D Latch with Clock S R D clk Q Q DQQ 00 QQ 01 QQ D Q Level Sensitive D Latch Clock high: set/reset (according to D) Clock low: keep state (ignore D)

16 Edge-Triggered D Flip-Flop D Flip-Flop Edge-Triggered Data is captured when clock is high Outputs change only on falling edges DQ Q DQ QLL clk D X Q c X c Q Q D

17 Registers Register D flip-flops in parallel shared clock extra clocked inputs: write_enable, reset, … clk D0 D3 D1 D bit reg

18 An Example: What will this circuit do? 32-bit reg Clk +1 Run WER Reset Decoder

19 Recap We can now build interesting devices with sensors Using combinatorial logic We can also store data values In state-holding elements Coupled with clocks

20 Administrivia Make sure partner in same Lab Section this week Lab2 is out Due in one week, next Monday, start early Work alone But, use your resources Lab Section, Piazza.com, Office Hours, Homework Help Session, Class notes, book, Sections, CSUGLab No Homework this week

21 Administrivia Check online syllabus/schedule Slides and Reading for lectures Office Hours Homework and Programming Assignments Prelims (in evenings): Tuesday, February 28 th Thursday, March 29 th Thursday, April 26 th Schedule is subject to change

22 Collaboration, Late, Re-grading Policies “Black Board” Collaboration Policy Can discuss approach together on a “black board” Leave and write up solution independently Do not copy solutions Late Policy Each person has a total of four “slip days” Max of two slip days for any individual assignment Slip days deducted first for any late assignment, cannot selectively apply slip days For projects, slip days are deducted from all partners 20% deducted per day late after slip days are exhausted Regrade policy Submit written request to lead TA, and lead TA will pick a different grader Submit another written request, lead TA will regrade directly Submit yet another written request for professor to regrade.

Finite State Machines

24 Revisit Voting Machine Ballots How do we create a vote counter machine detect enc LED decode

25 Revisit Voting Machine mux reg detect enc 3 decoder (3-to-8) 32 LED dec 3 WE +1 reg WE reg WE reg WE mux D V

26 Finite State Machines An electronic machine which has external inputs externally visible outputs internal state Output and next state depend on inputs current state

27 Abstract Model of FSM Machine is M = ( S, I, O,  ) S:Finite set of states I:Finite set of inputs O:Finite set of outputs  :State transition function Next state depends on present input and present state

28 Revisit Voting Machine mux reg detect enc 3 decoder (3-to-8) 32 LED dec 3 WE +1 reg WE reg WE reg WE mux

29 Automata Model Finite State Machine inputs from external world outputs to external world internal state combinational logic Next State Current State Input Output Registers Comb. Logic

30 FSM Example Legend state input/output start state A B CD down/on up/off down/on down/off up/off down/off up/off Input: up or down Output: on or off States: A, B, C, or D

31 FSM Example Legend S1S0S1S0 i0i1i2…/o0o1o2…i0i1i2…/o0o1o2… S1S0S1S0 / / / / / / / / Input: =up or =down Output: =on or =off States: =A, =B, =C, or =D

32 FSM Example Legend S1S0S1S0 i0i1i2…/o0o1o2…i0i1i2…/o0o1o2… S1S0S1S /11/1 0/00/0 1/11/1 1/01/0 0/00/0 1/01/0 0/00/0 0/00/0 Input: 0=up or 1=down Output: 1=on or 1=off States: 00=A, 01=B, 10=C, or 11=D

33 General Case: Mealy Machine Outputs and next state depend on both current state and input Mealy Machine Next State Current State Input Output Registers Comb. Logic

34 Moore Machine Special Case: Moore Machine Outputs depend only on current state Next State Current State Input Output Registers Comb. Logic

35 Moore Machine Example Legend state out input start out A off B on C off D on down up down up down up Input: up or down Output: on or off States: A, B, C, or D

36 Example: Digital Door Lock Digital Door Lock Inputs: keycodes from keypad clock Outputs: “unlock” signal display how many keys pressed so far

37 Door Lock: Inputs Assumptions: signals are synchronized to clock Password is B-A-B K A B KABMeaning 000Ø (no key) 110‘A’ pressed 101‘B’ pressed

38 Door Lock: Outputs Assumptions: High pulse on U unlocks door U D3D2D1D0D3D2D1D0 4 LED dec 8

39 Door Lock: Simplified State Diagram Idle G1 ”0” Ø G2 G3 B1B2 ”1””2” ”3”, U ”1””2” ØØ ØØ “B” “A”“B” else any else B3 ”3” else

40 Door Lock: Simplified State Diagram Idle G1 ”0” Ø G2 G3 B1B2 ”1””2” ”3”, U ”1””2” ØØ ØØ “B” “A”“B” else any else

41 Door Lock: Simplified State Diagram Idle G1 ”0” Ø G2 G3 B1B2 ”1””2” ”3”, U ”1””2” ØØ ØØ “B” “A”“B” else any else Cur. State Output Cur. State Output

42 Door Lock: Simplified State Diagram Idle G1 ”0” Ø G2 G3 B1B2 ”1””2” ”3”, U ”1””2” ØØ ØØ “B” “A”“B” else any else Cur. State Output Cur. State Output Idle“0” G1“1” G2“2” G3“3”, U B1“1” B2“2”

43 Door Lock: Simplified State Diagram Idle G1 ”0” Ø G2 G3 B1B2 ”1””2” ”3”, U ”1””2” ØØ ØØ “B” “A”“B” else any else Cur. StateInputNext State Cur. StateInputNext State

44 Door Lock: Simplified State Diagram Idle G1 ”0” Ø G2 G3 B1B2 ”1””2” ”3”, U ”1””2” ØØ ØØ “B” “A”“B” else any else Cur. StateInputNext State Cur. StateInputNext State IdleØ “B”G1 Idle“A”B1 G1Ø “A”G2 G1“B”B2 G2ØB2 G2“B”G3 G2“A”Idle G3anyIdle B1Ø KB2 Ø KIdle

45 Cur. StateInputNext State IdleØ “B”G1 Idle“A”B1 G1Ø “A”G2 G1“B”B2 G2ØB2 G2“B”G3 G2“A”Idle G3anyIdle B1Ø KB2 Ø KIdle State Table Encoding Cur. StateOutput Idle“0” G1“1” G2“2” G3“3”, U B1“1” B2“2” U D3D2D1D0D3D2D1D0 4 dec 8 D3D3 D2D2 D1D1 D0D0 U R P Q KABMeaning 000Ø (no key) 110‘A’ pressed 101‘B’ pressed KAB xxx 000 1xx 000 1xx S2S2 S1S1 S0S StateS2S2 S1S1 S0S0 Idle000 G1001 G2010 G3011 B1100 B2101 S2S2 S1S1 S0S0 S’ 2 S’ 1 S’

46 Door Lock: Implementation 4 dec 3bit Reg clk U D 3-0 S 2-0 S’ 2-0 S 2-0 A B C Strategy: (1) Draw a state diagram (e.g. Moore Machine) (2) Write output and next-state tables (3) Encode states, inputs, and outputs as bits (4) Determine logic equations for next state and outputs

47 Summary We can now build interesting devices with sensors Using combinational logic We can also store data values Stateful circuit elements (D Flip Flops, Registers, …) Clock to synchronize state changes But be wary of asynchronous (un-clocked) inputs State Machines or Ad-Hoc Circuits