Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania 18042 ECE 491 - Senior Design I Lecture 4 - Sequential Design.

Slides:



Advertisements
Similar presentations
Synchronous Sequential Logic
Advertisements

Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 13 - A Verilog.
Table 7.1 Verilog Operators.
CSE Spring Verilog for Sequential Systems - 1 Today: Verilog and Sequential Logic zFlip-flops yrepresentation of clocks - timing of state.
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.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE VLSI System Design Lecture 9 - ASM Diagrams.
Mini-MIPS From Weste/Harris CMOS VLSI Design. CS/EE 3710 Based on MIPS  In fact, it’s based on the multi-cycle MIPS from Patterson and Hennessy Your.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 14 - Multi-Cycle.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE VLSI Circuit Design Lecture 18 - Verilog.
EECE476 Lectures 10: Multi-cycle CPU Control Chapter 5: Section 5.5 The University of British ColumbiaEECE 476© 2005 Guy Lemieux.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Multi-Cycle Processor.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 4 - Verilog 2 (Sequential.
331 W10.1Spring :332:331 Computer Architecture and Assembly Language Spring 2005 Week 10 Building a Multi-Cycle Datapath [Adapted from Dave Patterson’s.
ENEE 408C Lab Capstone Project: Digital System Design Fall 2005 Sequential Circuit Design.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE VLSI System Design Lecture 4 - Advanced Verilog.
ELEN 468 Advanced Logic Design
Advanced Verilog EECS 270 v10/23/06.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Multi-Cycle Processor.
1 COMP541 State Machines – 2 Registers and Counters Montek Singh Feb 8, 2007.
Dr. Iyad F. Jafar Basic MIPS Architecture: Multi-Cycle Datapath and Control.
Overview Logistics Last lecture Today HW5 due today
Sequential Logic in Verilog
Chapter 4: Behavioral Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 4-1 Ders – 4: Davranışsal Modelleme.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Multi-Cycle Processor.
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.
ECE 551 Digital Design And Synthesis
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 COMP541 Sequential Circuits Montek Singh Feb 1, 2012.
Verilog for Synthesis Ing. Pullini Antonio
Computer Organization Lecture Set – 05.2 Chapter 5 Huei-Yung Lin.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 15 - Multi-Cycle.
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
Another Example: MIPS From the Harris/Weste book Based on the MIPS-like processor from the Hennessy/Patterson book.
Finite State Machine (FSM) Nattha Jindapetch December 2008.
Verilog A Hardware Description Language (HDL ) is a machine readable and human readable language for describing hardware. Verilog and VHDL are HDLs.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL State Machines Anselmo Lastra.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 12 - Introduction.
1 COMP541 State Machines - II Montek Singh Feb 13, 2012.
2/2/07EECS150 Lab Lecture #31 Verilog Synthesis & FSMs EECS150 Spring 2007 – Lab Lecture #3 Brent Mochizuki Greg Gibeling.
Verilog® HDL Behavioral Modeling (2)
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU 99-1 Under-Graduate Project Design of Datapath Controllers Speaker: Shao-Wei Feng Adviser:
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 9: State Machines & Reset Behavior Spring.
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part4: Verilog – Part 2.
Chapter 4 From: Dr. Iyad F. Jafar Basic MIPS Architecture: Multi-Cycle Datapath and Control.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
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 Lecture 3: Modeling Sequential Logic in Verilog HDL.
Figure Implementation of an FSM in a CPLD..
Design a MIPS Processor (II)
Figure 8.1. The general form of a sequential circuit.
ECE/CS 552: Multicycle Data Path
Extensions to the Multicycle CPU
D.4 Finite State Diagram for the Multi-cycle processor
Multi-Cycle CPU.
HDL Compiler Unsupport (Do NOT use in your verilog code)
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
Vishwani D. Agrawal James J. Danaher Professor
COE 202 Introduction to Verilog
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
Processor: Multi-Cycle Datapath & Control
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
The Verilog Hardware Description Language
Multi-Cycle Datapath Lecture notes from MKP, H. H. Lee and S. Yalamanchili.
Finite State Machine for Control
Dr. Tassadaq Hussain Introduction to Verilog – Part-4 Expressing FSM in Verilog (contd) and FSM State Encoding Dr. Tassadaq Hussain.
Verilog Synthesis & FSMs
Lecture 7: Verilog Part II
Presentation transcript:

Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 4 - Sequential Design in Verilog Fall 2008 Reading: Verilog Handout Sections 1-6 Verilog Coding Guidelines Sections 1-3

ECE 491 Fall 2008Lecture 4 - Sequential Verilog2 Today’s Outline  Sequential Logic in Verilog  Basic Constructs  Examples  Registered vs. Combinational Outputs  Lab 2 - Basic Sequential Logic  Finite State Machines  Discuss Lab 2

ECE 491 Fall 2008Lecture 4 - Sequential Verilog3 Sequential Design in Verilog - Basic Constructs  Describe edge-triggered behavior using:  always block with“edge event” clock-signal) clock-signal)  Nonblocking assignments ( <= clock-signal) begin output1 <= expression1;... output2 <= expression2;... end Registered Outputs for positive edge-trigger for negative edge-trigger Non-Blocking Assignments (deferred update)

ECE 491 Fall 2008Lecture 4 - Sequential Verilog4 Simple Examples: Flip-Flop, Register module flipflop(d, clk, q); input d; input clk; output q; reg q; clk) q <= d; endmodule module flop3(clk, d, q); input clk; input[3:0] d; output [3:0] q; reg[3:0] q; clk) q <= d; endmodule D CLK QD Q 44

ECE 491 Fall 2008Lecture 4 - Sequential Verilog5 Simple Example: Register with Reset  Synchronous - resets on clock edge if reset=1 module flopr(clk, reset, d, q); input clk; inputreset; input[3:0]d; output [3:0]q; reg[3:0] q; clk) if (reset) q <= 4’b0; else q <= d; endmodule D CLK Q 44 RESET

ECE 491 Fall 2008Lecture 4 - Sequential Verilog6 Simple Example: Register with Reset  Asynchronous - resets immediately if reset=1 module flopr(clk, reset, d, q); input clk; inputreset; input[3:0]d; output [3:0]q; reg[3:0] q; clk or posedge reset) if (reset) q <= 4’b0; else q <= d; endmodule D CLK Q 44 RESET CG 4.3:Use asynchronous reset only for system reset and initialization.

ECE 491 Fall 2008Lecture 4 - Sequential Verilog7 Another Example: Shift Register module shiftreg(clk, sin, q); input clk; inputsin; output [3:0]q; reg[3:0] q; clk) begin q[0] <= sin; q[1] <= q[0]; q[2] <= q[1]; q[3] <= q[2]; end endmodule Non-Blocking Assignments (update values after clock edge!) CG 4.2:Assign (registered) outputs using nonblocking (<=) assignment.

ECE 491 Fall 2008Lecture 4 - Sequential Verilog8 Blocking Assignments with Reg. Outputs module not_a_shiftreg(clk, sin, q); input clk; inputsin; output [3:0]q; reg[3:0] q; clk) begin q[0] = sin; q[1] = q[0]; q[2] = q[1]; q[3] = q[2]; end endmodule Blocking Assignments (update values immediately) CG 4.2:Assign (registered) outputs using nonblocking (<=) assignment.

ECE 491 Fall 2008Lecture 4 - Sequential Verilog9 Shift Register Application module debounce (pb, clk_100Hz, pb_debounced); input pb; input clk_100Hz; output pb_debounced; reg pb_debounced; reg [3:0] shift_pb; (posedge clk_100Hz) begin shift_pb [3:0] <= {shift_pb [2:0], pb}; if (shift_pb == 4'b1111) pb_debounced <= 1; else pb_debounced <= 0; end endmodule // debounce What does this circuit do? How does it work?

ECE 491 Fall 2008Lecture 4 - Sequential Verilog10 Another Example: 4-bit Counter  Basic Circuit: module counter(clk, Q); input clk; output [3:0] Q; reg [3:0] Q; // Q assigned a value in always posedge clk ) begin Q <= Q + 1; end endmodule  Questions: How about carry?  Putting carry in this code would “register” carry  Result: carry delayed one clock cycle  Need to mix sequential & combinational logic carry <= (Q == 4’b1111); // WRONG!

ECE 491 Fall 2008Lecture 4 - Sequential Verilog11 General Sequential Circuits  General circuit - both registered and comb. outputs  Approach: multiple always blocks clk) or assign

ECE 491 Fall 2008Lecture 4 - Sequential Verilog12 Registered Output Combinational Output Example: Adding carry to 4-bit Counter module counter(clk, Q, carry); input clk; output [3:0] Q; output carry; reg [3:0] Q; // Q assigned a value in always assign carry = (Q == 4'b1111); posedge clk ) begin Q <= Q + 1; end endmodule

ECE 491 Fall 2008Lecture 4 - Sequential Verilog13 Refining the Counter: Synchronous Reset module counter(clk, clr, Q, carry); input clk, clr; output [3:0] Q; output carry; reg [3:0] Q; // Q assigned a value in always assign carry = (Q == 4'b1111); posedge clk ) begin if (clr) Q <= 4'd0; else Q <= Q + 1; end endmodule Q changes on clk edge (usually preferred)

ECE 491 Fall 2008Lecture 4 - Sequential Verilog14 Refining the Counter: BCD Counter module bcdcounter(clk, reset, enb, Q, carry); input clk, reset, enb; output [3:0] Q; output carry; reg [3:0] Q; // a signal that is assigned a value assign carry = (Q == 9) & enb; posedge clk ) begin if (reset) Q <= 0; else if (enb) begin if (carry) Q <= 0; else Q <= Q + 1; end endmodule Q: How could we make a parameterized counter?

ECE 491 Fall 2008Lecture 4 - Sequential Verilog15 State Machine Design  Traditional Approach:  Create State Diagram  Create State Transition Table  Assign State Codes  Write Excitation Equations & Minimize  HDL-Based State Machine Design  Create State Diagram (optional)  Write HDL description of state machine  Synthesize

ECE 491 Fall 2008Lecture 4 - Sequential Verilog16 Review - State Transition Diagrams  "Bubbles" - states  Arrows - transition edges labeled with condition expressions  Example: Car Alarm arm door honk clk f clk = 1Hz

ECE 491 Fall 2008Lecture 4 - Sequential Verilog17 Review - State Transition Table  Transition List - lists edges in STD PSConditionNSOutput IDLEARM' + DOOR'IDLE0 IDLEARM*DOORBEEP0 BEEPARMWAIT1 BEEPARM'IDLE1 WAITARMBEEP0 WAITARM'IDLE0

ECE 491 Fall 2008Lecture 4 - Sequential Verilog18 Coding FSMs in Verilog - Standard Form  Clocked always block - state register  Combinational always block -  next state logic  output logic clk) CG 5.1:Use separate always blocks for sequential (state register) and combinational parts of the FSM.

ECE 491 Fall 2008Lecture 4 - Sequential Verilog19 Coding FSMs in Verilog - Code Skeleton  Part 1 - Declarations module fsm(inputs, outputs); input...; reg...; parameter [NBITS-1:0] S0 = 2'b00; S1 = 2'b01; S2 = 2b'10; S3 = 2b'11; reg [NBITS-1 :0] CURRENT_STATE; reg [NBITS-1 :0] NEXT_STATE; State Codes State Variable CG 5.3:Define state codes as symbolic constants using parameter.

ECE 491 Fall 2008Lecture 4 - Sequential Verilog20 Coding FSMs in Verilog - Code Skeleton  Part 2 - State Register, Logic Specification clk) begin if (reset) CURRRENT_STATE <= S0; else CURRENT_STATE <= NEXT_STATE; end or xin) begin... Assign default output values case (CURRENT_STATE) S0:... determine NEXT_STATE, outputs S1 :... determine NEXT_STATE, outputs...: default:... set NEXT_STATE, outputs for error end case end // always endmodule

ECE 491 Fall 2008Lecture 4 - Sequential Verilog21 FSM Example - Car Alarm  Part 1 - Declarations, State Register module car_alarm (arm, door, reset, clk, honk ); input arm, door, reset, clk; output honk; reg honk; parameter IDLE=0,BEEP=1,HWAIT=2; reg [1:0] current_state, next_state; clk) if (reset) current_state <= IDLE; else current_state <= next_state;

ECE 491 Fall 2008Lecture 4 - Sequential Verilog22 FSM Example - Car Alarm  Part 2 - Logic Specification or arm or door) begin honk = 0; // default value case (current_state) IDLE : begin honk = 0; if (arm && door) next_state = BEEP; else next_state = IDLE; end BEEP: begin honk = 1; if (arm) next_state = HWAIT; else next_state = IDLE; end

ECE 491 Fall 2008Lecture 4 - Sequential Verilog23 FSM Example - Car Alarm  Part 3 - Logic Specification (cont’d) HWAIT : begin honk = 0; if (arm) next_state = BEEP; else next_state = IDLE; end default : begin honk = 0; next_state = IDLE; end endcase end endmodule

ECE 491 Fall 2008Lecture 4 - Sequential Verilog24 Coding FSMs in Verilog - Alternate Form  Clocked always block - state register  Two separate combinational blocks  next state logic ( always )  output logic ( always or assign )

ECE 491 Fall 2008Lecture 4 - Sequential Verilog25 FSM Example - Verilog Handout  Divide-by-Three Counter S0 out=0 S1 out=0 S2 out=1 reset

ECE 491 Fall 2008Lecture 4 - Sequential Verilog26 Divide by Three Counter - Part 1 module divideby3FSM(clk, reset, out); inputclk; inputreset; outputout; reg[1:0] state; reg[1:0]nextstate; parameterS0 = 2’b00; parameterS1 = 2’b01; parameterS2 = 2’b10; // State Register clk) if (reset) state <= S0; else state <= nextstate;

ECE 491 Fall 2008Lecture 4 - Sequential Verilog27 Divide by Three Counter - Part 2 // Next State Logic case (state) S0: nextstate = S1; S1: nextstate = S2; S2: nextstate = S0; default: nextstate = S0; endcase // Output Logic assign out = (state == S2); endmodule

ECE 491 Fall 2008Lecture 4 - Sequential Verilog28 Larger Example: MIPS Control Unit

ECE 491 Fall 2008Lecture 4 - Sequential Verilog29 Review: Full Multicycle Implementation

ECE 491 Fall 2008Lecture 4 - Sequential Verilog30 MIPS Control Unit “Skeleton” - Part 1 module mips_control( clk, reset, Op, PCWrite, PCWriteCond, IorD, MemRead, MemWrite, MemtoReg, IRWrite, PCSource, ALUOp ALUSrcB, ALUSrcA, RegWrite, RegDst ); input clk; input reset; input [5:0] Op; output PCWrite; output PCWriteCond; output IorD; output MemRead; output MemWrite; output MemtoReg; output IRWrite; output [1:0] PCSource; output [1:0] ALUOp; output ALUSrcA; output [1:0] ALUSrcB; output RegWrite; output RegDst; port declarations

ECE 491 Fall 2008Lecture 4 - Sequential Verilog31 MIPS Control Unit “Skeleton” - Part 2 reg PCWrite; reg PCWriteCond; reg IorD; reg MemRead; reg MemWrite; reg MemtoReg; reg IRWrite; reg [1:0] PCSource; reg [1:0] ALUOp; reg ALUSrcA; reg [1:0] ALUSrcB; reg RegWrite; reg RegDst; parameter R_FORMAT = 6'd0; parameter LW = 6'd35; parameter SW = 6'd43; parameter BEQ = 6'd4; parameter J = 6’d2; parameter S0=4'd0, S1=4'd1, S2=4'd2, S3=4'd3, S4=4'd4, S5=4'd5, S6=4'd6, S7=4'D7, S8=4'd8, S9=4'd9; Symbolic Constants - opcodes Symbolic Constants - state codes reg declarations for output ports

ECE 491 Fall 2008Lecture 4 - Sequential Verilog32 MIPS Control Unit - Part 3 reg [3:0] current_state, next_state; clk) begin if (reset) current_state <= S0; else current_state <= next_state; end or Op) begin // default values PCWrite = 1'b0; PCWriteCond = 1'b0; IorD = 1'bx; MemRead = 1'b0; MemWrite = 1'b0; MemtoReg = 1'bx; IRWrite = 1'b0; PCSource = 2'bxx; ALUOp = 2'bxx; ALUSrcA = 1'bx; ALUSrcB = 2'bxx; RegWrite = 1'b0; RegDst = 1'bx; case (current_state) S0: begin MemRead = 1'b1; ALUSrcA = 1'b0; IorD = 1'b0; IRWrite = 1'b1; ALUSrcB = 2'b01; ALUOp = 2'b00; PCWrite = 1'b1; PCSource = 2'b00; next_state = S1; end … endcase end endmodule (More states here) Default Values More Default Values State S0 Full example at

ECE 491 Fall 2008Lecture 4 - Sequential Verilog33 Summary - Sequential Logic  Build sequential logic using  Clocked always for registered outputs Use non-blocking assignment “<=“  Combinational always or assign for comb. outputs Use blocking assignment “=“  Don’t use asynchronous reset  Use parameters for state codes in FSMs

ECE 491 Fall 2008Lecture 4 - Sequential Verilog34 Lab 2 Goals  Gain experience using Verilog for sequential logic  Gain experience using parameterized modules  Gain experience interfacing FPGA to I/O  Design building blocks that will be useful later  Design & debug a complete sequential circuit (stopwatch)

ECE 491 Fall 2008Lecture 4 - Sequential Verilog35 Lab 2 Overview 1.Parameterized counter (base on BCD example)  BW parameter: bitwidth  M parameter: counter modulus (counts from 0..M-1)  Inputs: clk, reset, enb  Outputs: Q, carry

ECE 491 Fall 2008Lecture 4 - Sequential Verilog36 Lab 2 Overview (cont’d) 2.Design module to divide 50 MHz down to 1000 Hz  Use parameterized counter to divide by 25,000  Use “T flip-flop” to give 50% duty cycle  Use common clock for all flip-flops  Don’t use common reset with logic driven by divider

ECE 491 Fall 2008Lecture 4 - Sequential Verilog37 Lab 2 Overview (cont’d) 3. 7-segment display control  Inputs: Four 4-bit BCD values, decimal points, “slow” clk  Outputs: segment enable, decimal point, 7-seg value

ECE 491 Fall 2008Lecture 4 - Sequential Verilog38 Lab 2 Overview (cont’d) 3. Design a stopwatch accurate to 1/1000 sec.  Buttons: clear - resets time to sec stop/start - alternately stops/starts count stop/startclear

ECE 491 Fall 2008Lecture 4 - Sequential Verilog39 Coming Up  Advanced Verilog  Behavioral Modeling and Simulation  Testbenches and Verification