Clocks and PLL CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos Prvulovic.

Slides:



Advertisements
Similar presentations
VERILOG: Synthesis - Combinational Logic Combination logic function can be expressed as: logic_output(t) = f(logic_inputs(t)) Rules Avoid technology dependent.
Advertisements

Simulation executable (simv)
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Synchronous Sequential Logic
Combinational Logic.
Table 7.1 Verilog Operators.
Reconfigurable Computing (EN2911X, Fall07) Lecture 04: Programmable Logic Technology (2/3) Prof. Sherief Reda Division of Engineering, Brown University.
Copyright 2001, Agrawal & BushnellVLSI Test: Lecture 261 Lecture 26 Logic BIST Architectures n Motivation n Built-in Logic Block Observer (BILBO) n Test.
//HDL Example 6-1 // //Behavioral description of //Universal shift register // Fig. 6-7 and Table 6-3 module shftreg.
ECE 551 Digital System Design & Synthesis Lecture 08 The Synthesis Process Constraints and Design Rules High-Level Synthesis Options.
Datorteknik DigitalCircuits bild 1 Combinational circuits Changes at inputs propagate at logic speed to outputs Not clocked No internal state (memoryless)
Digital Logic Chapter 5 Presented by Prof Tim Johnson
October 16, 2002Flip-flops1 Summary : Latches A sequential circuit has memory. It may respond differently to the same inputs, depending on its current.
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.
Flip-Flops Last time, we saw how latches can be used as memory in a circuit. Latches introduce new problems: We need to know when to enable a latch. We.
ECE 551 Digital System Design & Synthesis Lecture 09 Synthesis of Common Verilog Constructs.
CS 300 – Lecture 3 Intro to Computer Architecture / Assembly Language Sequential Circuits.
1 COMP541 Sequencing and Control Montek Singh Mar 29, 2007.
11/16/2004EE 42 fall 2004 lecture 331 Lecture #33: Some example circuits Last lecture: –Edge triggers –Registers This lecture: –Example circuits –shift.
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.
Overview Logistics Last lecture Today HW5 due today
ECE 551 Digital System Design & Synthesis Lecture 11 Verilog Design for Synthesis.
Registers CPE 49 RMUTI KOTAT.
ASIC/FPGA design flow. FPGA Design Flow Detailed (RTL) Design Detailed (RTL) Design Ideas (Specifications) Design Ideas (Specifications) Device Programming.
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
SEQUENTIAL CIRCUITS Component Design and Use. Register with Parallel Load  Register: Group of Flip-Flops  Ex: D Flip-Flops  Holds a Word of Data 
© 2003 Xilinx, Inc. All Rights Reserved Synchronous Design Techniques.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
ENG241 Digital Design Week #8 Registers and Counters.
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.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 7: Design Example, Modeling Flip-Flops Spring.
1 COMP541 Sequential Circuits Montek Singh Feb 1, 2012.
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
COMP541 Arithmetic Circuits
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
Lecture 7 Chap 9: Registers Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
MicroComputer Engineering DigitalCircuits slide 1 Combinational circuits Changes at inputs propagate at logic speed to outputs Not clocked No internal.
Design, Memory, and Debugging CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos.
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.
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.
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU 99-1 Under-Graduate Project Design of Datapath Controllers Speaker: Shao-Wei Feng Adviser:
Introduction to Verilog. Structure of a Verilog Program A Verilog program is structured as a set of modules, which may represent anything from a collection.
1 University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 Modeling Synchronous Logic Circuits Debdeep Mukhopadhyay Associate Professor Dept of Computer Science and Engineering NYU Shanghai and IIT Kharagpur.
1 Lecture 3: Modeling Sequential Logic in Verilog HDL.
Overview Logistics Last lecture Today HW5 due today
Supplement on Verilog FF circuit examples
Figure 8.1. The general form of a sequential circuit.
Registers and Counters
Last Lecture Talked about combinational logic always statements. e.g.,
Combinational circuits
Discussion 2: More to discuss
CS Fall 2005 – Lec. #5 – Sequential Logic - 1
SYNTHESIS OF SEQUENTIAL LOGIC
Logic Analyzers EECS150 Fall Lab Lecture #5 Arjun Singh
332:437 Lecture 8 Verilog and Finite State Machines
Flip-Flops Last time, we saw how latches can be used as memory in a circuit. Latches introduce new problems: We need to know when to enable a latch. We.
The Verilog Hardware Description Language
Logic Analyzers EECS150 Fall Lab Lecture #5 Arjun Singh
332:437 Lecture 8 Verilog and Finite State Machines
Instructor: Michael Greenbaum
Presentation transcript:

Clocks and PLL CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos Prvulovic

Asynchronous vs. Synchronious  Glitches and delays are very hard to deal with  People came up with synchronous circuits – There is a clock, all FFs trigger on clock edge – All signals only matter at the clock edge – Glitches and delays don’t matter, as long as new value stabilizes before the next clock edge – The clock signal had better not have any glitches!  Alternative: asynchronous circuits – no clock – Either design a glitch-free circuit, or – Generates a glitch-free “ready” signal when outputs are ready, use that to trigger next FF – Not easy to get the timing of the “ready” signal right 16 Jan 2014Lecture 4: Clocks and PLLs2

Clocking  We will make synchronous (clocked) designs – All FFs triggered by the same clock signal – No need to worry about glitches  What should be the clock frequency? – Clock Cycle Time must be long enough to accommodate delays along all paths in our design – Quartus compiler automatically computes these delays – So if our clock is too fast we get a Critical Warning  Do not overclock designs you submit for Projects! – Will lose points for doing that! – Design may not work at a different temperature, another instance of the DE-1 board, etc. 16 Jan 2014Lecture 4: Clocks and PLLs3

Timing Requirements  Clock cycle time computed from clock frequency  Delays on all paths computed from your design  Slack – time left over after all delays  Timing requirement => no negative slack  Project designs must meet timing requirements – Will lose points for submitting an overclocked design – Design may work when you test it! – But if it does not meet timing requirements, it is not guaranteed to work at different temperatures or on other boards 16 Jan 2014Lecture 4: Clocks and PLLs4

What to use as a clock signal  The board has a 50MHz clock (CLOCK_50) – There are two others, at 24MHz and a 27MHz  Will likely need a different clock frequency?  Clock divider can get us some lower frequencies – E.g. what if we flip a FF every cycle at 50MHz? – We get a 25MHz clock signal!  But what if we want 40MHz or 85MHz?  Answer: PLL (Phase-Locked Loop) 16 Jan 2014Lecture 4: Clocks and PLLs5

What is a PLL?  Phase-Locked Loop – Input: a clock signal at some frequency (e.g. 50MHz) – PLL can multiply frequency then divide it (50MHz*X/Y) Cheap PLL: X and Y are fixed, can get some particular frequency Fancy PLL: X and Y can be programmed – Lucky us – our board has a really fancy PLL Using the 50MHz clock as input, we can get a frequency that is just a bit lower to what we want Why not just a bit higher than what we want? – Can also control the duty cycle and phase shift Duty cycle: What part of the cycle is clock HIGH (default is 50%) Phase shift: Clock edge can be delayed relative to another clock Don’t mess with these settings If you need to change them, probably you are doing something wrong 16 Jan 2014Lecture 4: Clocks and PLLs6

Using PLLs  PLLs is a specialized circuit, can’t synthesize a really good one using logic gates and FFs  But our FPGA chip includes 4 such circuits – We just need to get Quartus to use one! – Use a Verilog module that maps to a PLL, then connect it properly  Use Quartus MegaWizard to generate PLL code – Tools -> Mega Wizard Plug-In Manager – Select “Create a new custom megafunction variation” – In the dialog, select Verilog, a file name (e.g. PLL.v) and select Installed Plug-Ins -> I/O -> ALTPLL 16 Jan 2014Lecture 4: Clocks and PLLs7

Configuring ALTPLL  Now we get to configure the PLL – Leave speed grade alone (our chip is speed grade 7) – Set input frequency to 50MHz (we will use CLOCK_50) – Leave PLL type and operation mode alone – On the next page, disable “areset” signal option, leave the option for the “locked” signal enabled, and enter 5000 in the “Hold locked input low…” box – Don’t create any additional clock inputs – For output clocks, we will only use c0 – Enter output clock frequency You give it a frequency, “Actual settings” displays what it can do Leave phase shift at 0 degrees and duty cycle at 50% for now – Later on, enable creation of the “Instantiation Template File” and click “Finish” 16 Jan 2014Lecture 4: Clocks and PLLs8

Adding a PLL to our circuit  Need to create a PLL instance and wire it up – Right-click in your Verilog code – Select “Insert Template” – In the dialog, go to “Megafunctions -> Instances”, find the PLL and select it, then click “Insert” – Now change the paramaters to match our processor E.g. we want “.inclk0(CLOCK_50)” Connect.c0 clock output to what you use as a clock (e.g. “.c0(clk)”)  Now we have a clock signal for the FFs in our design – Remember – synchronous design – All FFs clocked with the same clock! – Don’t use CLOCK_50 for some FFs and the PLL output for others!  Hmmm… what is this “locked” signal that PLL is producing? 16 Jan 2014Lecture 4: Clocks and PLLs9

The “locked” PLL signal  PLL takes time to achieve requested frequency – While it is “locking in”, clock frequency is unstable Some clock cycles too long (which is OK) But some are too short (not good, remember timing requirements) – Our design should wait until the clock is safe to use! clk) if(locked) state <= …; 16 Jan 2014Lecture 4: Clocks and PLLs10

Putting it all together wire clk,locked; Pll myPll(.inclk0(CLOCK_50),.c0(clk),.locked(locked)); wire reset=(!locked)|!KEY[0]; … clk or posedge reset) if(reset) begin some_var<=some_var_init_val; end else begin your normal code, e.g. some_var <=…; end 16 Jan 2014Lecture 4: Clocks and PLLs11

Resulting design: 16 Jan 2014Lecture 4: Clocks and PLLs12

Do this for all reg variables?  No, just the ones that matter – Some FFs need no initialization Can leave those uninitialized and/or assign w/o checking PLL lock  But easier to just init and lock-check everything – If something needed initialization and/or lock-check but you didn’t do it, the resulting bug is very hard to find – Heisenbug – sometimes it manifests, sometimes not – Whether a Heisenbug-infested design works or not depends on: Value that FF starts with How many cycles the PLL needs to lock Manufacturing variations (exact timing of gates on your board) Temperature (changes speed of gates) And many other things 16 Jan 2014Lecture 4: Clocks and PLLs13

What if I do this… clk or negedge lock) if(!lock) begin some_var<=some_var_init_val; end else begin your normal code, e.g. some_var <=…; end  Same behavior… but… – This puts initialization logic on every path! – With “or negedge lock”, uses SET/CLR inputs on FFs 16 Jan 2014Lecture 4: Clocks and PLLs14

Note the difference! 16 Jan 2014Lecture 4: Clocks and PLLs15

Extra Background on Initialization and Glitches 16

Our On/Off Switch Again module Lectures(LEDG, KEY); output [0:0] LEDG; input [3:0] KEY; wire flip = ! KEY[3]; reg state; flip) state <= !state; assign LEDG[0]=state; endmodule  Is LEDG[0] initially on or off? 16 Jan 2014Lecture 4: Clocks and PLLs17

Initialization module Lectures(LEDG, KEY); output [0:0] LEDG; input [3:0] KEY; wire flip = ! KEY[3]; reg state=0; flip) state <= !state; assign LEDG[0]=state; endmodule 16 Jan 2014Lecture 4: Clocks and PLLs18 The initial value of the “state” flip-flop should be zero

Initialization module Lectures(LEDG, KEY); output [0:0] LEDG; input [3:0] KEY; wire flip = ! KEY[3]; reg state; initial begin state=0; end flip) state <= !state; assign LEDG[0]=state; endmodule 16 Jan 2014Lecture 4: Clocks and PLLs19 Same as previous slide, but allows for more complex initialization Usually you put the “initial” statement where the “always” block for that FF is

Initialization and Reset module Lectures(LEDG, KEY); output [0:0] LEDG; input [3:0] KEY; wire flip = ! KEY[3]; wire reset=!KEY[2]; reg state; initial begin state=0; end flip or posedge reset) if(reset) state<=0; else state <= !state; assign LEDG[0]=state; endmodule 16 Jan 2014Lecture 4: Clocks and PLLs20 Allows us to initialize the state using a reset signal! Initialize the state when the board is turned on or programmed!

Glitches  Signals can briefly have wrong values – Due to logic delays and how they play together  Example: 4-bit adder – Inputs were 0000 and 0000, output is 0000 – Inputs change to 0001 and 1111, output stays 0000 – Actually, output changes briefly, then becomes 0000  Why? – Let’s just look at the MSB part of the adder – Takes two inputs and carry, produces output bit – Problem: takes time for carry to arrive, meanwhile MSB output is 1 16 Jan 2014Lecture 4: Clocks and PLLs21

Glitch demo reg [3:0] cntr1,cntr2; initial begin cntr1 = 4'h0; cntr2 = 4'h0; end mykey[3]) begin cntr1 <= cntr1+4'h1; cntr2 <= cntr2-4'h1; end wire [3:0] sum = cntr1 + cntr2; // Should always be 0000 wire sumnz = (sum != 0); // Should always be 0 reg [9:0] nzCnt; initial nzCnt = 0; sumnz) nzCnt <= nzCnt + 9'd1; assign LEDG = {sumnz,3'b0,sum}; assign LEDR=nzCnt; 16 Jan 2014Lecture 4: Clocks and PLLs22 Two counters that start at 0 and count in opposite directions Counts how many times sumnz became 1