Design, Memory, and Debugging CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos.

Slides:



Advertisements
Similar presentations
Simulation executable (simv)
Advertisements

Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Synchronous Sequential Logic
Combinational Logic.
Reconfigurable Computing S. Reda, Brown University Reconfigurable Computing (EN2911X, Fall07) Lecture 07: Verilog (3/3) Prof. Sherief Reda Division of.
Table 7.1 Verilog Operators.
Verilog Intro: Part 1.
Single-Cycle Processor Design CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 8: Sequential Design Spring 2009 W. Rhett.
1 COMP541 Sequential Circuits Montek Singh Sep 17, 2014.
Number Representation and Logic Design CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from.
Clocks and PLL CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos Prvulovic.
Verilog - 1 Writing Hardware Programs in Abstract Verilog  Abstract Verilog is a language with special semantics  Allows fine-grained parallelism to.
Specifies combinational logic (unclocked) always stmt. should use “=“ (called “blocking” assignment) in comb. logic always statements. RHS just takes output.
ECE 551 Digital System Design & Synthesis Lecture 09 Synthesis of Common Verilog Constructs.
2/16/2007EECS150 Lab Lecture #51 Logic Analyzers EECS150 Spring 2007 – Lab Lecture #5 Shah Bawany.
11/16/2004EE 42 fall 2004 lecture 331 Lecture #33: Some example circuits Last lecture: –Edge triggers –Registers This lecture: –Example circuits –shift.
1 COMP541 State Machines – 2 Registers and Counters Montek Singh Feb 8, 2007.
Today’s Lecture Process model –initial & always statements Assignments –Continuous & procedural assignments Timing Control System tasks.
A Tour of A Five-Stage Processor CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof.
Overview Logistics Last lecture Today HW5 due today
ECE 551 Digital System Design & Synthesis Lecture 11 Verilog Design for Synthesis.
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
B10010 Behavioral Verilog ENGR xD52 Eric VanWyk Fall 2012.
1 COMP541 Combinational Logic - 4 Montek Singh Jan 30, 2012.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Slide 1 6. VHDL/Verilog Behavioral Description. Slide 2 Verilog for Synthesis: Behavioral description Instead of instantiating components, describe them.
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.
PHY 201 (Blum)1 Microcode Source: Digital Computer Electronics (Malvino and Brown)
Computer Organization CS224 Fall 2012 Lesson 22. The Big Picture  The Five Classic Components of a Computer  Chapter 4 Topic: Processor Design Control.
Verilog for Synthesis Ing. Pullini Antonio
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities and architectural bodies behavioral,
IT253: Computer Organization Lecture 9: Making a Processor: Single-Cycle Processor Design Tonga Institute of Higher Education.
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
M.Mohajjel. Structured Procedures Two basic structured procedure statements always initial All behavioral statements appear only inside these blocks Each.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL State Machines Anselmo Lastra.
1 COMP541 State Machines – 2 Registers and Counters Montek Singh Feb 11, 2010.
COMP541 Sequential Circuits
Teaching Digital Logic courses with Altera Technology
Branch Prediction CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos Prvulovic.
1 COMP541 State Machines - II Montek Singh Feb 13, 2012.
Circuit Optimization CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos Prvulovic.
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
1 Modeling Synchronous Logic Circuits Debdeep Mukhopadhyay Associate Professor Dept of Computer Science and Engineering NYU Shanghai and IIT Kharagpur.
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.
Overview Logistics Last lecture Today HW5 due today
Supplement on Verilog FF circuit examples
Last Lecture Talked about combinational logic always statements. e.g.,
‘if-else’ & ‘case’ Statements
Registers and Counters
Example Best and Median Results
CS Fall 2005 – Lec. #5 – Sequential Logic - 1
Buttons and Debouncing Finite State Machine
SYNTHESIS OF SEQUENTIAL LOGIC
Registers and Counters
Logic Analyzers EECS150 Fall Lab Lecture #5 Arjun Singh
Debugging EECS150 Fall Lab Lecture #4 Sarah Swisher
Levels in Processor Design
Debugging EECS150 Fall Lab Lecture #4 Sarah Swisher
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
The Verilog Hardware Description Language
Logic Analyzers EECS150 Fall Lab Lecture #5 Arjun Singh
Registers and Counters
Levels in Processor Design
Verilog Synthesis & FSMs
Registers and Counters
Registers and Counters
Presentation transcript:

Design, Memory, and Debugging CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos Prvulovic

Base-10 Counting Example module Class(KEY,HEX0,HEX1); input [0:0] KEY; output [6:0] HEX0, HEX1; wire clock = ! KEY[0]; reg [3:0] cnthi, cntlo; clock) begin if(cntlo == 4'd9) begin cntlo <= 4'd0; if(cnthi == 4’d9) cnthi <= 4’d0; else cnthi <= cnthi + 4'd1; end else begin cntlo <= cntlo + 4'd1; end SevenSeg dlo(HEX0,cntlo); SevenSeg dhi(HEX1,cnthi); endmodule 21 Jan 2014Lecture 4: Clocks and PLLs2 module SevenSeg(sseg,num); output [6:0] sseg; input [1:0] num; assign sseg = (num == 2'd0) ? 7'b : (num == 2'd1) ? 7'b : (num == 2'd2) ? 7'b : … endmodule

Debugging our circuits  We can use “LED Debugging” – A close cousin to printf debugging – Use a LED to show the signal of interest, e.g. assign LEDG[0] = mysignal; – Then clock the circuit really slowly (e.g. using a KEY)  Problems with LED Debugging – Very tedious, takes a lot of time to get to the cycle you want (e.g. if the problem is in the 500 th cycle) – The key you use for clocking will wear out eventually Lecture 4: Clocks and PLLs323 Jan 2014

Debugging Demo  We will use SignalTap – Creates a little “oscilloscope” for your design and compiles it together with your design SignalTap stuff can be expensive (lots of memory bits and LEs) Can make design slower, too So remove SignalTap when bugs are fixed! Our demo design has 38LEs, 10Regs, 16K mem bits w/o SignalTap – Tools->”SignalTap II Logic Analyzer” First set your clock signal as the clock for SignalTap Set “Sample Depth” to # of cycles you want to record Right-click the “Instance” and Enable Power-Up Trigger Add wires/regs you want to record Recompile design, program board, then in SignalTap do “Read Data” Lecture 4: Clocks and PLLs423 Jan 2014

Debouncing  If it’s used as an edges-are-important signal, it needs a debouncing circuit: – Change output (debounced signal) only if input (SW signal) is stable for multiple clock periods. – This involves a counter, etc.  Why does KEY work just fine? – Because it is already debounced! – Board has a special circuit to “filter” and “condition” KEY signals, but no such circuit on SW Lecture 4: Clocks and PLLs523 Jan 2014

Using SW – Bouncing Effects  Try counting how many times SW[0] went 0->1  Doesn’t always work as expected – When we move the switch from 0 to 1 position, sometimes the count increment is >1 – When we move the switch from 1 to 0 position, sometimes the count changes!  What’s going on? Bouncing! 1.As contacts get close, vibration causes multiple “touches” before they are firmly together (or apart) 2.Sudden change in current causes voltage to bounce Lecture 4: Clocks and PLLs623 Jan 2014

Let’s see if you remember  If the highest clock frequency is 100MHz for this: reg [15:0] cnt; clock) cnt <= cnt + 16'd1;  What is the highest clock frequency for this: reg [15:0] upcnt,dncnt; clock) begin upcnt <= upcnt + 16'd1; dncnt <= dncnt - 16'd1; end 21 Jan 2014Lecture 4: Clocks and PLLs7

Let’s see if you remember  If the highest clock frequency is 100MHz for this: reg [15:0] cnt; clock) cnt <= cnt + 16'd1;  What is the highest clock frequency for this: reg [15:0] upcnt,dncnt; clock) begin upcnt <= upcnt + 16'd1; dncnt <= dncnt - 16'd1; end 21 Jan 2014Lecture 4: Clocks and PLLs8

Repetition in multi-bit signals  Example: sign-extender again module SXT(IN,OUT); parameter IBITS; parameter OBITS; input [(IBITS-1):0] IN; output [(OBITS-1):0] OUT; assign OUT={{(OBITS-IBITS){IN[IBITS-1]}},IN};; endmodule SXT #(.IBITS(4),.OBITS(8)) sxt1(SW[3:0],LEDG); 21 Jan 2014Lecture 4: Clocks and PLLs9

Using “=“ vs. “<=“  Two types of state assignment in Verilog – “=“ is called a “blocking” assignment – “<=“ is called a non-blocking assignment  We only used “<=“ until now – Computes RHS expression during the cycle – Latches value into LHS at end of cycle (e.g. posedge) – All “<=“ happen “simultaneously” (at clock edge)  Multiple “<=“ to the same reg? – block? Last one wins! – blocks? Conflict (can’t synthesize)! 21 Jan 2014Lecture 4: Clocks and PLLs10

What about “=“  Two big differences – Changes value of LHS as soon as RHS computed – Delays subsequent “=“ until the current one is done  What does this do? clock) begin stage1 <= stage2 + 1; stage2 <= stage1; end  What does this do? clock) begin stage1 = stage2 + 1; stage2 = stage1; end 21 Jan 2014Lecture 4: Clocks and PLLs11

Using “always” for combinatorial logic module ALU(A,B,CTL,OUT); parameter BITS; parameter CBITS; parameter CMD_ADD=0, CMD_SUB=1, CMD_LT=2, CMD_LE=3, CMD_AND=4, CMD_OR=5, CMD_XOR=6, CMD_NAND=7, CMD_NOR=8, CMD_NXOR=9; input [(CBITS-1):0] CTL; input [(BITS-1):0] A,B; output [(BITS-1):0] OUT; reg [(BITS-1):0] tmpout; or B or CTL) begin case(CTL) CMD_ADD: tmpout = A+B; CMD_SUB: tmpout = A-B; CMD_LT: tmpout = (A<B); CMD_LE: tmpout = (A<=B); CMD_AND: tmpout = A&B; CMD_OR: tmpout = A|B; CMD_XOR: tmpout = A^B; CMD_NAND: tmpout = ~(A&B); CMD_NOR: tmpout = ~(A|B); CMD_NXOR: tmpout = ~(A^B); default: tmpout = Something; endcase end assign OUT=tmpout; endmodule 21 Jan 2014Lecture 4: Clocks and PLLs12 tmpout is optimized out! But only if new value fully defined

Using “always” for combinatorial logic module ALU(A,B,CTL,OUT); parameter BITS; parameter CBITS; parameter CMD_ADD=0, CMD_SUB=1, CMD_LT=2, CMD_LE=3, CMD_AND=4, CMD_OR=5, CMD_XOR=6, CMD_NAND=7, CMD_NOR=8, CMD_NXOR=9; input [(CBITS-1):0] CTL; input [(BITS-1):0] A,B; output [(BITS-1):0] OUT; reg [(BITS-1):0] tmpout; or B or CTL) begin case(CTL) CMD_ADD: tmpout = A+B; CMD_SUB: tmpout = A-B; CMD_LT: tmpout = (A<B); CMD_LE: tmpout = (A<=B); CMD_AND: tmpout = A&B; CMD_OR: tmpout = A|B; CMD_XOR: tmpout = A^B; CMD_NAND: tmpout = ~(A&B); CMD_NOR: tmpout = ~(A|B); CMD_NXOR: tmpout = ~(A^B); default: tmpout = {BITS{1'bX}} ; endcase end assign OUT=tmpout; endmodule 21 Jan 2014Lecture 4: Clocks and PLLs13 What is X here?

Is FFFF<1 ? module ALU(A,B,CTL,OUT); parameter BITS; parameter CBITS; parameter CMD_ADD=0, CMD_SUB=1, CMD_LT=2, CMD_LE=3, CMD_AND=4, CMD_OR=5, CMD_XOR=6, CMD_NAND=7, CMD_NOR=8, CMD_NXOR=9; input [(CBITS-1):0] CTL; input [(BITS-1):0] A,B; output [(BITS-1):0] OUT; wire signed [(BITS-1):0] A,B; reg signed [(BITS-1):0] tmpout; or B or CTL) begin case(CTL) CMD_ADD: tmpout = A+B; CMD_SUB: tmpout = A-B; CMD_LT: tmpout = (A<B); CMD_LE: tmpout = (A<=B); CMD_AND: tmpout = A&B; CMD_OR: tmpout = A|B; CMD_XOR: tmpout = A^B; CMD_NAND: tmpout = ~(A&B); CMD_NOR: tmpout = ~(A|B); CMD_NXOR: tmpout = ~(A^B); default: tmpout = {CBITS{1'bX}} ; endcase end assign OUT=tmpout; endmodule 21 Jan 2014Lecture 4: Clocks and PLLs14

For loops  Example: sign-extender module module SXT(IN,OUT); parameter IBITS; parameter OBITS; input [(IBITS-1):0] IN; output [(OBITS-1):0] OUT; reg [(OBITS-1):0] tmpout; integer i; begin tmpout[(IBITS-1):0]=IN; for(i=IBITS;i<OBITS;i=i+1) begin tmpout[i]=IN[IBITS-1]; end assign OUT=tmpout; endmodule // This is how you can use this module: SXT #(.IBITS(4),.OBITS(8)) sxt1(SW[3:0],LEDG); 21 Jan 2014Lecture 4: Clocks and PLLs15

Parametrized modules  Example: code similar for 2-bit, 4-bit, etc. counter – Want to write one module for all of these module counter(IN,OUT); parameter BITS,INC; input IN; output [(BITS-1):0] OUT; reg [(BITS-1):0] state; IN) state<=state+INC; assign OUT=state; endmodule counter #(4,1) cnt1(clock,count); counter #(.INC(3),.BITS(8)) cnt2(clock,count); 21 Jan 2014Lecture 4: Clocks and PLLs16

Let’s see if you remember  If the highest clock frequency is 100MHz for this: reg [15:0] cnt; clock) cnt <= cnt + 16'd1;  What is the highest clock frequency for this: reg [15:0] upcnt,dncnt; clock) begin upcnt <= upcnt + 16'd1; dncnt <= dncnt - 16'd1; end 21 Jan 2014Lecture 4: Clocks and PLLs17

If-then-else within “always” clock) begin if(cnt == 2'd2) cnt <= 2'd0; else cnt <= cnt + 2'd1; end What does if-then-else translate into? 21 Jan 2014Lecture 4: Clocks and PLLs18 MUX

Memories in Verilog  What does this do? reg [15:0] mem;  It creates a 16-bit register (FF), mem[0] is LSB  What is a memory? – Conceptually, it’s a bunch of registers – We use an address to choose which one to access  In Verilog, we describe a memory like this: reg [15:0] mem[0:1023];  This “mem” has 1024 words, each with 16 bits Lecture 4: Clocks and PLLs1923 Jan 2014

Putting data in a memory  File -> New, then “Memory Initialization File” – Now we specify the “format” of the memory – And can edit the memory content – Or write a program to generate this content (Assign2)  Then tell Verilog to use this to initialize our “mem” (* ram_init_file = “SomeFile.mif" *) reg [15:0] mem[0:1023];  Each memory object can have one of these – E.g. if there is separate inst memory and data memory we can have different.mif files to initialize them Lecture 4: Clocks and PLLs2023 Jan 2014

Example! (* ram_init_file = "Mem.mif" *) reg [15:0] mem[0:1023]; // 1024-entry, 16-bit memory reg [15:0] mdr; // 16-bit MDR register reg [9:0] mar; // 10-bit MAR register initial mar = 10'd0; // MAR starts with value zero clock) begin mdr <= mem[mar]; // Read memory mar <= mar + 10’d1; // And increment mar register end // Do something with MDR, e.g. display it: SevenSeg sseg0(.IN(mdr[ 3: 0]),.OUT(HEX0)); SevenSeg sseg1(.IN(mdr[ 7: 4]),.OUT(HEX1)); SevenSeg sseg2(.IN(mdr[11: 8]),.OUT(HEX2)); SevenSeg sseg3(.IN(mdr[15:12]),.OUT(HEX3)); Lecture 4: Clocks and PLLs2123 Jan 2014

Let’s try without the MDR! clock) begin mar <= mar + 10’d1; // Increment mar register end // Do something with MDR, e.g. display it: SevenSeg sseg0(.IN(mem[mar][ 3: 0]),.OUT(HEX0)); SevenSeg sseg1(.IN(mem[mar][ 7: 4]),.OUT(HEX1)); SevenSeg sseg2(.IN(mem[mar][11: 8]),.OUT(HEX2)); SevenSeg sseg3(.IN(mem[mar][15:12]),.OUT(HEX3)); Compiles (not syntax error). But doesn’t work! 23 Jan 2014Lecture 4: Clocks and PLLs22

This works… but our memory is optimized out! clock) begin mar <= mar + 10’d1; // Increment mar register end wire [15:0] memout=mem[mar]; // Do something with MDR, e.g. display it: SevenSeg sseg0(.IN(memout[ 3: 0]),.OUT(HEX0)); SevenSeg sseg1(.IN(memout[ 7: 4]),.OUT(HEX1)); SevenSeg sseg2(.IN(memout[11: 8]),.OUT(HEX2)); SevenSeg sseg3(.IN(memout[15:12]),.OUT(HEX3)); Lecture 4: Clocks and PLLs2323 Jan 2014

Getting memory to behave…  This (almost) always works as expected – Memory address for reading comes from a FF (reg) – Value read from memory only latched into FF (reg) No logic that “sees” the value directly  (Almost) everything else can misbehave – Unless you know exactly what you are doing Sometimes you still get surprised  Why? Will come back to this eventually – For now, just read memory using FFs Lecture 4: Clocks and PLLs2423 Jan 2014

Debugging our circuits  We can use “LED Debugging” – A close cousin to printf debugging – Use a LED to show the signal of interest, e.g. assign LEDG[0] = mysignal; – Then clock the circuit really slowly (e.g. using a KEY)  Problems with LED Debugging – Very tedious, takes a lot of time to get to the cycle you want (e.g. if the problem is in the 500 th cycle) – The key you use for clocking will wear out eventually Lecture 4: Clocks and PLLs2523 Jan 2014

Debugging Demo  We will use SignalTap – Creates a little “oscilloscope” for your design and compiles it together with your design SignalTap stuff can be expensive (lots of memory bits and LEs) Can make design slower, too So remove SignalTap when bugs are fixed! Our demo design has 38LEs, 10Regs, 16K mem bits w/o SignalTap – Tools->”SignalTap II Logic Analyzer” First set your clock signal as the clock for SignalTap Set “Sample Depth” to # of cycles you want to record Right-click the “Instance” and Enable Power-Up Trigger Add wires/regs you want to record Recompile design, program board, then in SignalTap do “Read Data” Lecture 4: Clocks and PLLs2623 Jan 2014

Using SW – Bouncing Effects  Try counting how many times SW[0] went 0->1  Doesn’t always work as expected – When we move the switch from 0 to 1 position, sometimes the count increment is >1 – When we move the switch from 1 to 0 position, sometimes the count changes!  What’s going on? Bouncing! 1.As contacts get close, vibration causes multiple “touches” before they are firmly together (or apart) 2.Sudden change in current causes voltage to bounce Lecture 4: Clocks and PLLs2723 Jan 2014

Debouncing  If it’s used as an edges-are-important signal, it needs a debouncing circuit: – Change output (debounced signal) only if input (SW signal) is stable for multiple clock periods. – This involves a counter, etc.  Why does KEY work just fine? – Because it is already debounced! – Board has a special circuit to “filter” and “condition” KEY signals, but no such circuit on SW Lecture 4: Clocks and PLLs2823 Jan 2014

Key presses…  But how do we do clear, stopped, running? reg clear=1’b1,running=1’b0,stopped=1’b0; KEY[0]) {clear,running,stopped}<= {stopped,clear,running};  Nooooo! This is NOT a synchronous design!  How about… clk) if(!KEY[0]) {clear,running,stopped}<= {stopped,clear,running};  Now it’s synchronous… but incorrect  Project 1 Tips and Tricks2916 Jan 2014

Key presses… reg [3:0] oldKEY=4'b1111; clk) oldKEY<=KEY; wire KEY0Pushed= {oldKEY[0],KEY[0]}==2'b10;  Now we can do clk) if(KEY0Pushed) {clear,running,stopped}<= {stopped,clear,running}; Project 1 Tips and Tricks3016 Jan 2014

How do we choose the frequency?  Using timing analysis results!  Compile design, look at Compilation Report – Under “TimeQuest Timing Analyzer”, Click on “Slow Model”, then “Fmax Summary” – It tells you the max frequency for your design  Fmax higher than your PLL’s frequency – Increase the PLL frequency (faster processor)  Fmax lower than your PLL’s frequency? – There will be a critical warning – Don’t submit projects that have this warning! – Design will be graded as incorrect! Even if it works! 16 Jan 2014Lecture 4: Clocks and PLLs31

The rest of it…  Lap-time functionality (KEY[1]) – Another set of regs to hold lap time – Display selects between time and lap time How do we select?  Get rid of the / and % for seconds – How? Project 1 Tips and Tricks3216 Jan 2014