The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL State Machines Anselmo Lastra.

Slides:



Advertisements
Similar presentations
COMP541 State Machines – II: Verilog Descriptions
Advertisements

Synchronous Sequential Logic
Table 7.1 Verilog Operators.
Verilog. 2 Behavioral Description initial:  is executed once at the beginning. always:  is repeated until the end of simulation.
FSM Revisit Synchronous sequential circuit can be drawn like below  These are called FSMs  Super-important in digital circuit design FSM is composed.
Digital Electronics Chapter 5 Synchronous Sequential Logic.
Slide 1 7. Verilog: Combinational always statements. VHDL: Combinational Processes: To avoid (I.E. DO NOT What in your HDL code?) Cases that generate Synthesis.
1 COMP541 Sequential Circuits Montek Singh Sep 17, 2014.
CSE Spring Verilog for Sequential Systems - 1 Today: Verilog and Sequential Logic zFlip-flops yrepresentation of clocks - timing of state.
FSM examples.
Spring 20067W. Rhett Davis with minor modifications by Dean Brock ECE 406 at UNASlide 1 ECE 406 Design of Complex Digital Systems Lecture 10: 9: State.
ECE 331 – Digital System Design
1 COMP541 Sequencing and Control Montek Singh Mar 29, 2007.
Verilog Sequential Circuits Ibrahim Korpeoglu. Verilog can be used to describe storage elements and sequential circuits as well. So far continuous assignment.
1 COMP541 State Machines Montek Singh Feb 6, 2007.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 4 - Verilog 2 (Sequential.
ELEN 468 Advanced Logic Design
1 COMP541 State Machines – 2 Registers and Counters Montek Singh Feb 8, 2007.
Sequential circuit design
Lecture 10 Topics: Sequential circuits Basic concepts Clocks
Overview Logistics Last lecture Today HW5 due today
Sequential Logic in Verilog
1 Chapter 5 Synchronous Sequential Logic 5-1 Sequential Circuits Every digital system is likely to have combinational circuits, most systems encountered.
1 COMP541 State Machines Montek Singh Feb 8, 2012.
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Ders 8: FSM Gerçekleme ve.
1/8/ L20 Project Step 8 - Data Path Copyright Joanne DeGroat, ECE, OSU1 State Machine Design with an HDL A methodology that works for documenting.
EEE2243 Digital System Design Chapter 4: Verilog HDL (Sequential) by Muhazam Mustapha, January 2011.
Slide 1 6. VHDL/Verilog Behavioral Description. Slide 2 Verilog for Synthesis: Behavioral description Instead of instantiating components, describe them.
ECE/CS 352 Digital System Fundamentals© 2001 C. Kime 1 ECE/CS 352 Digital Systems Fundamentals Spring 2001 Chapters 3 and 4: Verilog – Part 2 Charles R.
1 CSE-308 Digital System Design (DSD) N-W.F.P. University of Engineering & Technology, Peshawar.
1 COMP541 Sequential Circuits Montek Singh Feb 1, 2012.
1 Finite State Machines (FSMs) Now that we understand sequential circuits, we can use them to build: Synchronous (Clocked) Finite State Machines Finite.
Finite State Machine (FSM) Nattha Jindapetch December 2008.
Registers; State Machines Analysis Section 7-1 Section 5-4.
Introduction to ASIC flow and Verilog HDL
1 COMP541 State Machines – 2 Registers and Counters Montek Singh Feb 11, 2010.
ENG241 Digital Design Week #7 Sequential Circuits (Part B)
1 COMP541 Finite State Machines - 1 Montek Singh Sep 22, 2014.
SYEN 3330 Digital SystemsJung H. Kim 1 SYEN 3330 Digital Systems Chapter 6 – Part 4.
1 COMP541 State Machines - II Montek Singh Feb 13, 2012.
2/3/2006EECS150 Lab Lecture #31 Implementation of FSMs EECS150 Spring 2006 – Lab Lecture #3 Guang Yang Greg Gibeling.
2/2/07EECS150 Lab Lecture #31 Verilog Synthesis & FSMs EECS150 Spring 2007 – Lab Lecture #3 Brent Mochizuki Greg Gibeling.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Logic Design Dr. Oliver Faust.
Sequential Circuit Design Section State Machines Design Procedure 1.Specification- obtain (produce) problem description 2.Formulation - Obtain.
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU 99-1 Under-Graduate Project Design of Datapath Controllers Speaker: Shao-Wei Feng Adviser:
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part4: Verilog – Part 2.
Sequential Circuit Design 05 Acknowledgement: Most of the following slides are adapted from Prof. Kale's slides at UIUC, USA.
EMT 351/4 DIGITAL IC DESIGN Verilog Behavioral Modeling  Finite State Machine -Moore & Mealy Machine -State Encoding Techniques.
Pusat Pengajian Kejuruteraan Mikroelektronik EMT 351/4 DIGITAL IC DESIGN Verilog Behavioural Modeling (Part 4) Week #
1 COMP541 Sequential Logic – 2: Finite State Machines Montek Singh Feb 29, 2016.
1 Lecture 3: Modeling Sequential Logic in Verilog HDL.
Exp#7 Finite State Machine Design in Verilog COE203 Digital Logic Laboratory Dr. Ahmad Almulhem KFUPM Spring 2009.
Supplement on Verilog FF circuit examples
Week #7 Sequential Circuits (Part B)
Figure 8.1. The general form of a sequential circuit.
Sequential Circuit Design
Last Lecture Talked about combinational logic always statements. e.g.,
© Copyright 2004, Gaetano Borriello and Randy H. Katz
COMP541 Sequential Logic – 2: Finite State Machines
Buttons and Debouncing Finite State Machine
COMP541 State Machines Montek Singh Feb 4, 2010.
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
332:437 Lecture 8 Verilog and Finite State Machines
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
The Verilog Hardware Description Language
Verilog Synthesis & FSMs
EGR 2131 Unit 12 Synchronous Sequential Circuits
332:437 Lecture 8 Verilog and Finite State Machines
Presentation transcript:

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL State Machines Anselmo Lastra

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 2 Topics How to design machines that go through a sequence of events Basically close this loop

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 3 Lab Preview Digital lock You’ll need clock Will provide code for slowing clock ♦ Next slide ♦ There are better ways to change clock speed. Will discuss later.

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 4 Counter module cntr(output out, input clk); reg [31:0] count; (posedge clk) count <= count + 1; assign out = count[22]; endmodule What does this do?

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 5 Button and Debouncing Button normally high Mechanical switches can “bounce” ♦ Go H and L a number of times We’ll want to ♦ debounce ♦ synchronize

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 6 Flip-Flop for pushbutton module button_test( output q, input btn, input clk ); reg q; (posedge clk) begin if(btn == 1) q <= 1; else q <= 0; end endmodule What is this?

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 7 Simple Module to Begin With module led_on(output s6, input button, input clk); wire clkb; //opt cntr C1(clkb, clk); button_test B1(s6, ~button, clkb); endmodule clk to board clock, P88 button to pushbutton, P93 Why ~button? s6 to one of LED segments

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 8 Things to Think About Can I press button and not light LED? What happens if I hold button down for a long time? What effect will changing period of clkb have? ♦ On LED ♦ On button debouncing What does it mean to “press the button”? ♦ Think carefully about this

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 9 Analysis of Sequential Circuits Earlier we learned how to analyze combinational circuits Now extend to synchronous sequential ♦ Include time We’ll use state tables and state diagrams

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 10 Input Equations Can describe inputs to FF with logic equations

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 11 Time is Implied Note that last circuit used the ♦ Previous state to determine next state ♦ State and inputs to determine outputs Synchronous circuit When are transitions? So timing is discrete

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 12 State Table Just truth table with state added

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 13 Another Table Same info, different layout style

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 14 Sequential Circuit Types Moore model – outputs depend on states Mealy model – outputs also depend on inputs

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 15 State Diagram Alternative representation for state table Moore-> State/Output Inputs

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 16 Mealy Model Output depends on input and state Input/Output

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 17 State Table vs. Diagram Same information Table is perhaps easier to fill in from description Diagram is perhaps easier to understand ♦ You can label states with English description

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 18 Design Procedure Take problem description and refine it into a state table or diagram Assign codes to the states Write Verilog ♦ See example in a moment ♦ Designing with gates and FFs more involved because you have to derive input and output functions

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Good Place to go off on a Tangent

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 20 Example – Sequence Recognizer Circuit has input, X, and output, Z Recognizes sequence 1101 on X ♦ Specifically, if X has been 110 and next bit is 1, make Z high

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 21 How to Design States States remember past history Clearly must remember we’ve seen 110 when next 1 comes along Tell me one necessary state

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 22 Beginning State Some state, A If 1 appears, move to next state B Input / Output

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 23 Second 1 New state, C To reach C, must have seen 11

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 24 Next a 0 If 110 has been received, go to D Next 1 will generate a 1 on output Z

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 25 What else? What happens to arrow on right? Must go to some state. Where?

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 26 What Sequence? Here we have to interpret problem We’ve just seen 01 ♦ Is this beginning of new 1101? ♦ Or do we need to start over w/ another 1? They decide that it’s beginning (01…)

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 27 Cover every possibility Well, must have every possibility out of every state In this case, just two: X = 0 or 1 You fill in other cases

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 28 Fill in

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 29 Answer From Book

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 30 State Minimization When we make state diagram, do we need all those states? Some may be redundant State minimization procedures can be used ♦ We won’t cover now

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 31 How to code in Verilog Instead of learning how to hand design (Sections 4-6 and 4-7) Learn how to code this in Verilog

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 32 Verilog Case Statement Similar to sequence of if/then/else case (expression) case: statements; other case: statements; default: statements;// optional endcase Example in a moment

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 33 Parameter – Just Shorthand module seq_rec_v(CLK, RESET, X, Z); input CLK, RESET, X; output Z; reg [1:0] state, next_state; parameter A = 2'b00, B = 2'b01, C = 2 'b10, D = 2'b11; Notice that we’ve assigned codes to the states – more later

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 34 Next State or state) begin case (state) A: if (X == 1) next_state <= B; else next_state <= A; B: if(X) next_state <= C;else next_state <= A; C: if(X) next_state <= C;else next_state <= D; D: if(X) next_state <= B;else next_state <= A; endcase end The last 3 cases do same thing. Just sparse syntax.

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 35 On Reset or CLK CLK or posedge RESET) begin if (RESET == 1) state <= A; else state <= next_state; end Notice that state only gets updated on posedge of clock (or on reset)

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 36 Output or state) begin case(state) A: Z <= 0; B: Z <= 0; C: Z <= 0; D: Z <= X ? 1 : 0; endcase end

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 37 Synthesis of Latches Sometimes unexpected latches created always will try to synthesize FF if (select) out <= A; ♦ To save old value if select != 1 If cover all possibilities, no FF if (select) out <= A; else out <= B;

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 38 Comment on Book Code Could shorten Don’t need next_state, for example ♦ Can just set state on clock ♦ Note that the two are a little different in function Don’t need three always clauses ♦ Although it’s easier to have combinational code to set output be separate Template helps synthesizer ♦ Check to see whether your state machines were recognized

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 39 Read 7-1 and 7-11 Lab ♦ I’d suggest spending time thinking about the lock

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 40 Today Simple state machines ♦ How to code them in Verilog Next Week ♦ More on state machine styles ♦ Registers ♦ Counters ♦ Info for next lab VGA timing

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 41

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 42 BACKUP

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL 43 One Shot Help me analyze this one What does it do?