verilog tutorial - ucsbstrukov/ece154a/labs/verilog.pdf · verilog tutorial adapted from krste...

71
Verilog Tutorial Adapted from Krste Asanovic

Upload: others

Post on 02-Apr-2020

28 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Verilog Tutorial

Adapted from Krste Asanovic

Page 2: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Verilog Fundamentals

• History

• Data types

• Structural Verilog

• Functional Verilog

Page 3: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Originally designers used manual translation + bread boards for verification

Page 4: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Hardware design languages enabled logic level simulation and verification

Page 5: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Once design were written in HDLs tools could be used for automatic translation

Page 6: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Primary Verilog data type is a bit-vector where bits can take on one of four values

Page 7: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

The Verilog keyword wire is used to denote a standard hardware net

Page 8: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Verilog includes ways to specify bit literals in various bases

Page 9: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Verilog Basics

• Data types

• Structural Verilog

• Functional Verilog

Page 10: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

A Verilog module includes a module name and a port list

Page 11: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

A Verilog module includes a module name and a port list

Page 12: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

A module can instantiate other modules creating a module hierarchy

Page 13: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

A module can instantiate other modules creating a module hierarchy

Page 14: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

A module can instantiate other modules creating a module hierarchy

Page 15: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Verilog supports connecting ports by position and by name

Page 16: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Let’s review how to turn our schematic diagram into structural Verilog

Page 17: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Let’s review how to turn our schematic diagram into structural Verilog

Page 18: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Verilog Fundamentals

• Data types

• Structural Verilog

• Functional Verilog

– Gate level

– Register transfer level

– High-level behavioral

Page 19: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Functional Verilog can roughly be divided into three abstraction levels

Page 20: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Gate-level Verilog uses structural Verilogto connect primitive gates

Page 21: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Continuous assignments statementsassign one net to another or to a literal

Page 22: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Using continuous assignments to implement an RTL four input mutliplexer

Page 23: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Verilog RTL includes many operators in addition to basic boolean logic

Page 24: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Verilog RTL operators

Page 25: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Always blocks have parallel inter-block and sequential intra-block sematics

Page 26: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Always blocks have parallel inter-block and sequential intra-block sematics

Page 27: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Always blocks have parallel inter-block and sequential intra-block sematics

Page 28: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Always blocks have parallel inter-block and sequential intra-block sematics

Page 29: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Always blocks have parallel inter-block and sequential intra-block sematics

Page 30: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Continuous and procedural assignment statements are very different

Page 31: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Always blocks can contain more advanced control constructs

Page 32: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

What happens if the case statement is not complete?

Page 33: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

What happens if the case statement is not complete?

Page 34: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

So is this how we make latches and flip-flops?

Page 35: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

To understand why we need to know more about Verilog execution semantics

Page 36: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

To understand why we need to know more about Verilog execution semantics

Page 37: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

To understand why we need to know more about Verilog execution semantics

Page 38: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

To understand why we need to know more about Verilog execution sematics

Page 39: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

To understand why we need to know more about Verilog execution sematics

Page 40: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

To understand why we need to know more about Verilog execution semantics

Page 41: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

To understand why we need to know more about Verilog execution semantics

Page 42: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

To understand why we need to know more about Verilog execution sematics

Page 43: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

To understand why we need to know more about Verilog execution sematics

Page 44: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

We didn’t model what we expected due to Verilog execution semantics

Page 45: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Non-blocking procedural assignments add an extra event queue

Page 46: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Non-blocking procedural assignments add an extra event queue

Page 47: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

The order of non-blocking assignments does not matter

Page 48: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Common patterns for latch and flip-flop inference

Page 49: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Writing Good Synthesizable Verilog

Page 50: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Behavioral Verilog is used to model the abstract function of a hardware

Page 51: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Verilog can be used to model the high-level behavior of a hardware block

Page 52: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Delay statements should only be used in test harnesses

Page 53: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

System tasks are used for test harnesses and simulation management

Page 54: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Which abstraction is the right one?

Page 55: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Examples

Page 56: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Mux4: Gate-level structural Verilog

Page 57: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Mux4: Using continuous assignments

Page 58: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Mux4: Behavioral style

Page 59: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Mux4: Using always block

Page 60: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Mux4: Always block permit more advanced sequential idioms

Page 61: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Parametrized mux4

Page 62: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Flip-flops

Page 63: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Flip-flops with reset

Page 64: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Register

Page 65: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Register in terms of Flip-flops

Page 66: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Static Elaboration: Generate

Page 67: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

A simple state machine for valid/ready signals

Page 68: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Implementing the control logic finite state machine in Verilog

Page 69: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Implementing the control signal outputs for the finite state machine

Page 70: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Implementing the state transitions for the finite state machine

Page 71: Verilog Tutorial - UCSBstrukov/ece154a/labs/verilog.pdf · Verilog Tutorial Adapted from Krste Asanovic. Verilog Fundamentals •History •Data types •Structural Verilog •Functional

Take away points