Verilog: always @ Blocks



Similar documents
LAB #4 Sequential Logic, Latches, Flip-Flops, Shift Registers, and Counters

Modeling Sequential Elements with Verilog. Prof. Chien-Nan Liu TEL: ext: Sequential Circuit

CHAPTER 11 LATCHES AND FLIP-FLOPS

Life Cycle of a Memory Request. Ring Example: 2 requests for lock 17

A New Paradigm for Synchronous State Machine Design in Verilog

ECE 451 Verilog Exercises. Sept 14, James Barnes

Design Example: Counters. Design Example: Counters. 3-Bit Binary Counter. 3-Bit Binary Counter. Other useful counters:

Traffic Light Controller. Digital Systems Design. Dr. Ted Shaneyfelt

Engr354: Digital Logic Circuits

More Verilog. 8-bit Register with Synchronous Reset. Shift Register Example. N-bit Register with Asynchronous Reset.

A Verilog HDL Test Bench Primer Application Note

Registers & Counters

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Gates, Circuits, and Boolean Algebra

Digital Design Verification

Flip-Flops, Registers, Counters, and a Simple Processor

ECE232: Hardware Organization and Design. Part 3: Verilog Tutorial. Basic Verilog

Introduction to Functional Verification. Niels Burkhardt

EE 42/100 Lecture 24: Latches and Flip Flops. Rev B 4/21/2010 (2:04 PM) Prof. Ali M. Niknejad

Lecture 7: Clocking of VLSI Systems

SEQUENTIAL CIRCUITS. Block diagram. Flip Flop. S-R Flip Flop. Block Diagram. Circuit Diagram

Sequential Logic. (Materials taken from: Principles of Computer Hardware by Alan Clements )

Lecture 8: Synchronous Digital Systems

Ladder and Functional Block Programming

Multiplexers Two Types + Verilog

Digital Electronics Detailed Outline

7. Latches and Flip-Flops

Lab #5: Design Example: Keypad Scanner and Encoder - Part 1 (120 pts)

AC : PRACTICAL DESIGN PROJECTS UTILIZING COMPLEX PROGRAMMABLE LOGIC DEVICES (CPLD)

Testing & Verification of Digital Circuits ECE/CS 5745/6745. Hardware Verification using Symbolic Computation

So far we have investigated combinational logic for which the output of the logic devices/circuits depends only on the present state of the inputs.

Flip-Flops and Sequential Circuit Design. ECE 152A Winter 2012

Flip-Flops and Sequential Circuit Design

2 : BISTABLES. In this Chapter, you will find out about bistables which are the fundamental building blocks of electronic counting circuits.

if-then else : 2-1 mux mux: process (A, B, Select) begin if (select= 1 ) then Z <= A; else Z <= B; end if; end process;

Lesson 12 Sequential Circuits: Flip-Flops

Modeling Registers and Counters

Latches, the D Flip-Flop & Counter Design. ECE 152A Winter 2012

University of Toronto Faculty of Applied Science and Engineering

CHAPTER 11: Flip Flops

Having read this workbook you should be able to: recognise the arrangement of NAND gates used to form an S-R flip-flop.

Chapter 7: Advanced Modeling Techniques

After opening the Programs> Xilinx ISE 8.1i > Project Navigator, you will come to this screen as start-up.

EXPERIMENT 8. Flip-Flops and Sequential Circuits

CNC FOR EDM MACHINE TOOL HARDWARE STRUCTURE. Ioan Lemeni

Memory Elements. Combinational logic cannot remember

INTRODUCTION TO DIGITAL SYSTEMS. IMPLEMENTATION: MODULES (ICs) AND NETWORKS IMPLEMENTATION OF ALGORITHMS IN HARDWARE

Understanding Verilog Blocking and Non-blocking Assignments

1. True or False? A voltage level in the range 0 to 2 volts is interpreted as a binary 1.

Introduction to CMOS VLSI Design (E158) Lecture 8: Clocking of VLSI Systems

Finite State Machine Design A Vending Machine

Testing Low Power Designs with Power-Aware Test Manage Manufacturing Test Power Issues with DFTMAX and TetraMAX

Modeling Latches and Flip-flops

Understanding the IEC Programming Languages

Asynchronous counters, except for the first block, work independently from a system clock.

Upon completion of unit 1.1, students will be able to

EE552. Advanced Logic Design and Switching Theory. Metastability. Ashirwad Bahukhandi. (Ashirwad Bahukhandi)

Combinational Logic Design Process

Linear Motion and Assembly Technologies Pneumatics Service. Understanding the IEC Programming Languages

ECE380 Digital Logic

Digital Systems. Role of the Digital Engineer

Manchester Encoder-Decoder for Xilinx CPLDs

Chapter 2 Ensuring RTL Intent

Lecture-3 MEMORY: Development of Memory:

CHAPTER 3 Boolean Algebra and Digital Logic

Getting the Most Out of Synthesis

Active Learning in the Introduction to Digital Logic Design Laboratory Course

An Innocent Investigation

Sequential Logic: Clocks, Registers, etc.

Computer Science 217

ESP-CV Custom Design Formal Equivalence Checking Based on Symbolic Simulation

Set-Reset (SR) Latch

To design digital counter circuits using JK-Flip-Flop. To implement counter using 74LS193 IC.

CSE140: Midterm 1 Solution and Rubric

Arbs2U Is it right for me? 17 October 2014

A Digital Timer Implementation using 7 Segment Displays

An Integer Square Root Algorithm

ModelSim-Altera Software Simulation User Guide

WEEK 8.1 Registers and Counters. ECE124 Digital Circuits and Systems Page 1

ASYNCHRONOUS COUNTERS

CS311 Lecture: Sequential Circuits

Class Assignment. College Bus Graphics Design VCP DIGITAL IMAGING III ASSIGNMENT DUE OCTOBER 25 TH FALL 2010

Assertion Synthesis Enabling Assertion-Based Verification For Simulation, Formal and Emulation Flows

Master/Slave Flip Flops

Theory of Logic Circuits. Laboratory manual. Exercise 3

Wiki Lab Book. This week is practice for wiki usage during the project.

16-bit ALU, Register File and Memory Write Interface

Adder.PPT(10/1/2009) 5.1. Lecture 13. Adder Circuits

6. BOOLEAN LOGIC DESIGN

DIGITAL COUNTERS. Q B Q A = 00 initially. Q B Q A = 01 after the first clock pulse.

E158 Intro to CMOS VLSI Design. Alarm Clock

Grading Benchmarks FIRST GRADE. Trimester st Student has achieved reading success at. Trimester st In above grade-level books, the

Finite State Machine Design and VHDL Coding Techniques

Systems I: Computer Organization and Architecture

Mentor Tools tutorial Bold Browser Design Manager Design Architect Library Components Quicksim Creating and Compiling the VHDL Model.

STRING TELEPHONES. Education Development Center, Inc. DESIGN IT! ENGINEERING IN AFTER SCHOOL PROGRAMS. KELVIN Stock #651817

The Association of System Performance Professionals

3. VERILOG HARDWARE DESCRIPTION LANGUAGE

Transcription:

Verilog: always @ Blocks hris Fletcher U Berkeley Version 0.2008.9.4 September 5, 2008 Introduction Sections. to.6 discuss always@ blocks in Verilog, and when to use the two major flavors of always@ block, namely the always@( * ) and always@(posedge lock) block.. always@ Blocks always@ blocks are used to describe events that should happen under certain conditions. always@ blocks are always followed by a set of parentheses, a begin, some code, and an end. Program shows a skeleton always@ block. Program The skeleton of an always@ block always @(... sensitivity list... ) begin 2... elements... In Program, the sensitivity list is discussed in greater detail in Section.5. The contents of the always@ block, namely elements describe elements that should be set when the sensitivity list is satisfied. For now, just know that when the sensitivity list is satisfied, the elements inside the always@ block are set/updated. They are not otherwise. Elements in an always@ block are set/updated in sequentially and in parallel, depending on the type of assignment used. There are two types of assignments: <= (non-blocking) and = (blocking)..2 <= (non-blocking) ssignments Non-blocking assignments happen in parallel. In other words, if an always@ block contains multiple <= assignments, which are literally written in Verilog sequentially, you should think of all of the assignments being set at exactly the same time. For example, consider Program 2. Program 2 <= assignments inside of an always@ block 4 always @(... sensitivity list... ) begin 5 B <= ; 6 <= B; 7 D <= ; 8 end Program 2 specifies a circuit that reads when the sensitivity list is satisfied, B gets s value, gets B s old value, and D gets s old value. The key here is that gets B s old value, etc (read: think OLD

value!. This ensures that is not set to, as is B s new value, as of the always@ block s execution. Non-blocking assignments are used when specifying sequential logic (see Section.4)..3 = (blocking) ssignments Blocking assignments happen sequentially. In other words, if an always@ block contains multiple = assignments, you should think of the assignments being set one after another. For example, consider Program 3. Program 3 = assignments inside of an always@ block always @(... sensitivity list... ) begin 2 B = ; 3 = B; 4 D = ; Program 3 specifies a circuit that reads when the sensitivity list is satisfied, B gets, gets B, and D gets. But, by the time gets B, B has been set to. Likewise, by the time D gets, has been set to B, which, as we stated above, has been set to. This always@ block turns B,, and D into. Blocking assignments are used when specifying combinational logic (see Section.5)..4 always@(posedge lock) Blocks always@(posedge lock) ( always at the positive edge of the clock ) or always@(negedge lock) ( always at the negative edge of the clock ) blocks are used to describe Sequential Logic, or Registers. Only <= (non-blocking) assignments should be used in an always@(posedge lock) block. Never use = (blocking) assignments in always@(posedge lock) blocks. Only use always@(posedge lock) blocks when you want to infer an element(s) that changes its value at the positive or negative edge of the clock. For example, consider Figure, a recreation of Program 2 that uses posedge lock as its sensitivity list. Figure is also known as a shift register. The completed always@ block is shown in Program 4. Figure shift register B D lock.5 always@( * ) Blocks always@( * ) blocks are used to describe ombinational Logic, or Logic Gates. Only = (blocking) assignments should be used in an always@( * ) block. Never use <= (non-blocking) assignments in always@( * ) blocks. Only use always@( * ) block when you want to infer an element(s) that changes its value as soon as one or more of its inputs change. This point might be confusing. We said that non-blocking statements happen in parallel. Yet, they are useful for specifying sequential logic? In digital design, sequential logic doesn t refer to things happening in parallel or a sequence, as we have been discussing, but rather to logic that has state. 2

Program 4 shift register, using <= assignments inside of an always@(posedge lock) block always @( posedge lock ) begin 2 B <= ; 3 <= B; 4 D <= ; lways use * (star) for your sensitivity list in always@( * ) blocks. The sensitivity list specifies which signals should trigger the elements inside the always@ block to be updated. For example, given 3 wires, B and, we can create an and gate through Program 5, and shown graphically in Figure 2. Program 5 n and gate inside of an always@( * ) block always @( or B) begin 2 = & B; Figure 2 The and gate produced by Program 5 (this is a normal and gate!) B Program 5 specifies that when or B change values, update the value of every element inside the always@( * ) block. In this case, the only element inside the always@( * ) block is, which in this case is assigned the and of and B. very common bug is to introduce an incomplete sensitivity list. See Program 6 for two examples of incomplete sensitivity lists. Program 6 n and gate with an incomplete sensitivity list (this is incorrect!) always @( ) begin 2 = & B; always @( B) begin 2 = & B; In Program 6, the first example produces an and gate that only updates its output when changes. If B changes, but does not change, does not change because the always@() block isn t executed. Likewise, the second example produces an and gate that doesn t react to a change in. Incomplete sensitivity lists are almost NEVER what you want! They introduce very hard-to-find bugs. s such, we use always@( * ). The * is shorthand for always@( or B) in our examples. In other words, * sets the sensitivity list to any values that can have an impact on a value(s) determined by the always@( * ) block. * provides a bug-free shorthand for creating complete sensitivity lists. 3

.6 Pitfalls You might be wondering what happens if you don t follow the conventions set forth in Sections.4 and.5. The following are some easy-to-make mistakes in Verilog that can have a dramatic [and undesired] effect on a circuit.. onsider the shift register from Figure. If you place = assignments inside of an always@(posedge lock) block to produce the shift register, you instead get the parallel registers shown in Figure 3 and Program 7. You might also get one register, whose output is tied to B, and D. Both possible outcomes are equivelent. These circuit make sense, but don t create shift registers! (s shift registers are common construct, we assume that you wanted to create a shift register) Figure 3 Parallel registers lock B D Program 7 Parallel registers, using = assignments inside of an always@(posedge lock) block always @( posedge lock ) begin 2 B = ; 3 = B; 4 D = ; 2. The opposite example (shown in Program 8), where we place <= assignments inside of always@( * ) is less pronounced. In this case, just consider what type of circuit you want to create: do you want all statements to be executed in parallel or in sequence (see Section.2 and.3)? In the always@( * ), the distinction between <= and = is sometimes very subtle, as the point of always@ ( * ) is to trigger at indefinite times (unlike the very definite posedge lock). We recommend = in conjunction with always@( * ) to establish good convention (as = was originally meant to be associated with combinational logic). Program 8 <= assignments inside of always@( * ) blocks always @( * ) begin 2 B <= ; 3 <= B; 4 D <= ; 3. onsider the case of incompletely specified sensitivity lists. n incompletely specified sensitivity list, as discussed in Section.5, will create an always@ block that doesn t always set/update its elements when it should. In truth, synthesis tools will often know what you mean if you provide an incomplete sensitivity list, and pretend that your sensitivity list was complete. This is not the 4

case with simulation tools (like ModelSim), however. ModelSim will not correct your sensitivity list bugs, and your simulations will be plagued with odd errors. Furthermore, the synthesis tools catching your errors is not guarenteed. n easy way to avoid these potential problems is to use always@( * ) as opposed to always@(input or Input 2 or...). 4. Lastly, a very subtle point which perhaps has the potential to cause the most frustration is latch generation. If you don t assign every element that can be assigned inside an always@( * ) block every time that always@( * ) block is executed, a latch (similar to a register but much harder to work with in FPGs) will be inferred for that element. This is never what you want and is a terrible place for bugs. s this is subtle, it is somewhat hard to visualize. onsider Program 9. Program 9 n always@( * ) block that will generate a latch for wire Trigger, Pass ; 2 reg, ; 3 4 always @( * ) begin 5 = b0; 6 if ( Trigger ) begin 7 = Pass ; 8 = Pass ; 9 end 0 end In Program 9, and are both assigned in at least one place inside the always@ block. is always assigned at least once. This is because the first line of the always@ block specifies a default value for. This is a perfectly valid assignment. It ensures that is always assigned with each execution of the always@ block. on the other hand is not always assigned. When Trigger = b, the if statement executes and both and get set. If Trigger = b0, however, the if is skipped. is safe, as it was given a default value on the first line of the always@ block. on the other hand, doesn t get assigned at all when this happens. s such, a latch is inferred for. The erroneous circuit depicted in Program 9 is shown in Figure 4. Figure 4 The circuit generated by Program 9 (this is an erroneous circuit!) Pass Trigger Latch 'b0 0 To fix this problem, we must make sure that gets set every time the always@ block is executed. simple way to force this is to add another default value, depicted in Program 0 and shown in Figure 5. 5

Program 0 n always@( * ) block that will not generate latches wire Trigger, Pass ; 2 reg, ; 3 4 always @( * ) begin 5 = b0; 6 = b; 7 if ( Trigger ) begin 8 = Pass ; 9 = Pass ; 0 end end Figure 5 The circuit generated by Program 0 (this is correct!) Pass Trigger 'b 0 'b0 0 Default values are an easy way to avoid latch generation, however, will sometimes break the logic in a design. s such, other ways of ensuring that each value always gets set are going to be worth looking into. Typically, they involve proper use of the Verilog else statement, and other flow constructs. Know that setting a reg to itself is not an acceptable way to ensure that the reg always gets set. For example, = ; enjected into the top of the always@( * ) block in Program 9 will not supress latch generation. In every execution of an always@( * ) block, each value that is assigned in at least one place must be assigned to a non-trivial value during every execution of the always@( * ) block. 6