332:437 Lecture 9 Verilog Example

Slides:



Advertisements
Similar presentations
Digital System Design-II (CSEB312)
Advertisements

Verilog Fundamentals Shubham Singh Junior Undergrad. Electrical Engineering.
//HDL Example 8-2 // //RTL description of design example (Fig.8-9) module Example_RTL (S,CLK,Clr,E,F,A);
Counters Discussion D8.3.
Traffic light contoller using FSM
CDA 3100 Recitation Week 11.
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Sequential Logic in Verilog
Synchronous Sequential Logic
EE 361 Fall 2003University of Hawaii1 Hardware Design Tips EE 361 University of Hawaii.
Verilog Modules for Common Digital Functions
Table 7.1 Verilog Operators.
CSE 201 Computer Logic Design * * * * * * * Verilog Modeling
//HDL Example 5-1 // //Description of D latch (See Fig.5-6) module D_latch (Q,D,control); output Q; input.
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.
Give qualifications of instructors: DAP
//HDL Example 6-1 // //Behavioral description of //Universal shift register // Fig. 6-7 and Table 6-3 module shftreg.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 8: Sequential Design Spring 2009 W. Rhett.
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.
CS 151 Digital Systems Design Lecture 37 Register Transfer Level
Pulse-Width Modulated DAC
Conditional Statements  if and else if statements if (expression) if (expression) statements statements { else if (expression) { else if (expression)
Verilog Sequential Circuits Ibrahim Korpeoglu. Verilog can be used to describe storage elements and sequential circuits as well. So far continuous assignment.
ELEN 468 Advanced Logic Design
Verilog Descriptions of Digital Systems. Electronic Lock // // Electronic combinational lock // module lock(seg7,key, valid_key, col, row, mclk, resetL)
Sequential Logic in Verilog
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.
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 COMP541 Sequential Circuits Montek Singh Feb 1, 2012.
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
Final Project. System Overview Description of Inputs reset: When LOW, a power on reset is performed. mode: When LOW, NORMal mode selected When HIGH,
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL State Machines Anselmo Lastra.
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part4: Verilog – Part 2.
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 #
Lecture 5. Verilog HDL #3 Prof. Taeweon Suh Computer Science & Engineering Korea University COSE221, COMP211 Logic Design.
1 Lecture 3: Modeling Sequential Logic in Verilog HDL.
Figure Implementation of an FSM in a CPLD..
Exp#7 Finite State Machine Design in Verilog COE203 Digital Logic Laboratory Dr. Ahmad Almulhem KFUPM Spring 2009.
Overview Logistics Last lecture Today HW5 due today
Supplement on Verilog FF circuit examples
Supplement on Verilog for Algorithm State Machine Chart
Figure 8.1. The general form of a sequential circuit.
Last Lecture Talked about combinational logic always statements. e.g.,
EMT 351/4 DIGITAL IC DESIGN Week # Synthesis of Sequential Logic 10.
‘if-else’ & ‘case’ Statements
Supplement on Verilog Sequential circuit examples: FSM
Digital Logic Design Digital Design, M. Morris Mano and Michael D
HDL Compiler Unsupport (Do NOT use in your verilog code)
SYNTHESIS OF SEQUENTIAL LOGIC
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
COE 202 Introduction to Verilog
Topics Verilog styles for sequential machines. Flip-flops and latches.
Supplement on Verilog Sequential circuit examples: FSM
Register-Transfer Level Components in Verilog
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
The Verilog Hardware Description Language
Lecture 4: Continuation of SystemVerilog
332:437 Lecture 9 Verilog Example
Dr. Tassadaq Hussain Introduction to Verilog – Part-4 Expressing FSM in Verilog (contd) and FSM State Encoding Dr. Tassadaq Hussain.
332:437 Lecture 8 Verilog and Finite State Machines
332:437 Lecture 9 Verilog Example
Lecture 7: Verilog Part II
Presentation transcript:

332:437 Lecture 9 Verilog Example Verilog Design Methodology Pinball Machine Verilog Coding States State transition diagram Final Verilog Code Summary 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Verilog Design Methodology Draw a System Block Diagram As if you were designing the hardware by hand Label all signals For each block: Determine whether it is controlled by clocks or reset signals If so, it is sequential If not, it is combinational 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Verilog Design Methodology Combinational blocks Map into combinational always block or into assign statement Sequential blocks Map into always block controlled by: {posedge, negedge} clk {posedge, negedge} reset, set 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Verilog Design Methodology Add an initial block for the testbench Add additional always block to generate the clock Add additional sequential always blocks for every counter 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Example -- Design a Pinball Machine After left-flipper or right-flipper pressed If ball in 100 point slot, + 100 pt (green) If ball in 200 point slot, + 200 pt (yellow) If 3 200 point hits in a row, enable big_bopper slot (red) If big_bopper slot enabled and hit (gold), Get 600 points Increment free_game count If ball_lost, go back to start state 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Hardware Visualization 100 200 bop_hit green yellow red Gold bop_en Next State Decoder Output Clock Generator State Register Point Counter Game Testbench pgames ppoints 5/4/2019 Bushnell: Digital Systems Design Lecture 9

State Transition Diagram Need these states: init – initialize the machine start – waiting for input h200one – hit 200 point hole once h200two – hit 200 point hole twice h200three – hit 200 point hole 3 X 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Bushnell: Digital Systems Design Lecture 9 Verilog Coding Write an always block for each box on the prior slide One exception – combine next state and output decoders into 1 always block Why? For clarity Less code to write Guaranteed that both decoders activate under same conditions 5/4/2019 Bushnell: Digital Systems Design Lecture 9

State Transition Diagram ball_lost neither ball_lost neither init start h200one h200 h100 h100 h100 ball_lost h200 h100 ball_lost h200two h200 h200three neither bop_hit h200 neither 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Evolution of Verilog Code Combined next state and output decoders into one always block for clarity design_analyzer objected to clock generator process – moved it to the testbench Forgot to code hardware for bop_enable – fixed that vcs objected to the @(*) sensitivity list of clock generator – combined it with rest of testbench Corrected testbench and it worked! 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Bushnell: Digital Systems Design Lecture 9 Module Declaration module pinballmachine (input clk, reset_bar, output reg [0:2] pstate, output reg [0:2] nstate, output reg [0:4] games, output reg [0:15] points, output reg [0:4] pgames, output reg [0:15] ppoints, input h100, h200, bop_hit, ball_lost, output reg bop_en, green, yellow, red, gold); 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Bushnell: Digital Systems Design Lecture 9 Declaration of states parameter init = 0, start = 1, h200one = 2, h200two = 3, h200three = 4; 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Bushnell: Digital Systems Design Lecture 9 State Flip-flops // State flipflops always @(posedge clk, negedge reset_bar) begin if (reset_bar == 0) pstate <= init; else pstate <= nstate; end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder // Next state and output decoder always @(*) begin case (pstate) init: begin nstate <= start; points <= 0; games <= 0; green <= 0; yellow <= 0; red <= 0; gold <= 0; bop_en <= 0; end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder start:begin bop_en <= 0; if (! ball_lost) begin if (h100 == 1) begin nstate <= start; points <= ppoints + 100; games <= 0; green <= 1; yellow <= 0; red <= 0; gold <= 0; end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder else if (h200 == 1) begin nstate <= h200one; points <= ppoints + 200; games <= 0; green <= 0; yellow <= 1; red <= 0; gold <= 0; end else begin nstate <= start; points <= 0; games <= 0; end end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder else begin nstate <= start; points <= 0; games <= 0; green <= 0; yellow <= 0; red <= 0; gold <= 0; end end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder h200one: begin bop_en <= 0; if (! ball_lost) begin if (h100 == 1) begin nstate <= start; points <= ppoints + 100; games <= 0; green <= 1; yellow <= 0; red <= 0; gold <= 0; end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder else if (h200 == 1) begin nstate <= h200two; points <= ppoints + 200; games <= 0; green <= 0; yellow <= 1; red <= 0; gold <= 0; end else begin nstate <= h200one; points <= 0; games <= 0; end end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder else begin nstate <= start; points <= 0; games <= 0; green <= 0; yellow <= 0; red <= 0; gold <= 0; end end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder h200two: begin if (! ball_lost) begin if (h100 == 1) begin nstate <= start; points <= ppoints + 100; games <= 0; green <= 1; yellow <= 0; red <= 0; gold <= 0; bop_en <= 0; end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder else if (h200 == 1) begin nstate <= h200three; points <= ppoints + 200; games <= 0; green <= 0; yellow <= 0; red <= 1; gold <= 0; bop_en <= 1; end else begin nstate <= h200two; points <= 0; games <= 0; end end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder else begin nstate <= start; points <= 0; games <= 0; green <= 0; yellow <= 0; red <= 0; gold <= 0; bop_en <= 0; end end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder h200three: begin if (! ball_lost) begin if (h100 == 1) begin nstate <= start; points <= ppoints + 100; games <= 0; green <= 1; yellow <= 0; red <= 0; gold <= 0; bop_en <= 0; end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder else if (h200 == 1) begin nstate <= start; points <= ppoints + 200; games <= 0; green <= 0; yellow <= 1; red <= 0; gold <= 0; bop_en <= 0; end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder else if (bop_hit == 1) begin nstate <= start; points <= ppoints + 600; games <= pgames + 1; green <= 0; yellow <= 0; red <= 0; gold <= 1; bop_en <= 0; end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Next State/Output Decoder else begin nstate <= h200three; points <= 0; games <= 0; end end else begin nstate <= start; points <= 0; games <= 0; green <= 0; yellow <= 0; red <= 0; gold <= 0; bop_en <= 0; end end endcase end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Bushnell: Digital Systems Design Lecture 9 Point Counter // Point counter always @(posedge clk, negedge reset_bar) begin if (reset_bar == 0) ppoints <= 0; else if (points) ppoints <= points; end 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Bushnell: Digital Systems Design Lecture 9 Game Counter // Game counter always @(posedge clk, negedge reset_bar) begin if (reset_bar == 0) pgames <= 0; else if (games) pgames <= games; end endmodule 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Bushnell: Digital Systems Design Lecture 9 system Module module system (); wire clk; wire reset_bar; wire [0:2] pstate; wire [0:2] nstate; wire [0:4] games; wire [0:15] points; wire [0:4] pgames; wire [0:15] ppoints; wire h100, h200, bop_hit, ball_lost; wire bop_en; wire green, yellow, red, gold; pinballmachine (clk, reset_bar, pstate, nstate, games, points, pgames, ppoints, h100, h200, bop_hit, ball_lost, bop_en, green, yellow, red, gold); testbench (clk, reset_bar, pstate, nstate, games, points, pgames, ppoints, h100, h200, bop_hit, ball_lost, bop_en, green, yellow, red, gold); endmodule 5/4/2019 Bushnell: Digital Systems Design Lecture 9

Bushnell: Digital Systems Design Lecture 9 Summary Still need to visualize the hardware as combinational and sequential blocks in block diagram when using Verilog Still need to design tight state transition diagram Blocks in diagram translate into always/assign statements 5/4/2019 Bushnell: Digital Systems Design Lecture 9