digital system design verilog ® hdl useful modeling techniques maziar goudarzi

30
Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

Upload: conrad-cummings

Post on 22-Dec-2015

260 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

Digital System Design

Verilog® HDLUseful Modeling Techniques

Maziar Goudarzi

Page 2: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 2

Today Program

Procedural Continuous AssignmentOverriding ParametersConditional Compilation and ExecutionUseful System Tasks

Page 3: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

Procedural Continuous Assignment

Useful Modeling Techniques

Page 4: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 4

Procedural Continuous Assignment

Overrides, for a certain time, the effect of regular assignments to a variable.

Two types assign/deassign

Works only on register data types force/release

Works on both register and net data types

Note: Not synthesizable. Use only for modeling and simulation

Page 5: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 5

Procedural Continuous Assignment (cont’d)assign/deassign

Keywordsassign: overrides regular procedural assignments

• LHS: reg or concatenation of regs. No nets. No arrays. No bit-select or part-select

deassign: re-enables regular procedural assignments

After deassign: Last value remains on the register until a new

procedural assignment changes it.

Page 6: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 6

Page 7: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 7

Procedural Continuous Assignment (cont’d)

force/release Keywords:

force: overrides all procedural/continuous/ procedural continuous assignments

release: re-enables other assignments Hence, assignments in priority order:

1. force

2. assign (procedural continuous)

3. Procedural/continuous assignments

Page 8: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 8

force/release on reg variables

Page 9: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 9

force/release on nets

Net value immediately returns to its normal assigned value when released

Page 10: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

Overriding Parameters

Useful Modeling Techniques

Page 11: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 11

Overriding Parameters

Two methods defparam statement Module instance parameter value assignment

defparam statement Keyword: defparam Syntax:

defparam <parameter_hierarchical_name>=<value>;

Page 12: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 12

Page 13: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 13

Overriding Parameters (cont’d)

Module instance parameter values Parameters are overridden when the module is

instantiated Syntax:

<module_name> #(<param_vals>) <instance_name>;

Page 14: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 14

Example with multiple parameters

Page 15: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

Conditional Compilation and Execution

Useful Modeling Techniques

Page 16: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 16

Conditional Compilation

Usage: To compile some part of code under certain

conditions

Keywords: ‘ifdef, `else, `endif ‘define to define the flag

Page 17: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 17

Page 18: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 18

Conditional Execution

Usage: To execute some part of code when a flag is set at runtime Used only in behavioral modeling

Keywords: $test$plusargs

Syntax: $test$plusargs( <argument_to_check> )

Page 19: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 19

Page 20: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

Useful System Tasks

Useful Modeling Techniques

Page 21: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 21

Useful System TasksFile Output

Opening a file Syntax:

<file_handle> = $fopen( “<file_name>” ); <file_handle> is a 32 bit value, called multi-channel descriptor Only 1 bit is set in each descriptor Standard output has a descriptor of 1 (Channel 0)

Page 22: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 22

Useful System TasksFile Output (cont’d)

Writing to files $fdisplay, $fmonitor, $fstrobe $strobe, $fstrobe

The same as $display, $fdisplay, but executed after all other statements schedule in the same simulation time

Syntax: $fdisplay(<handle>, p1, p2,…, pn);

Closing files$fclose(<handle>);

Page 23: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 23

Example: Simultaneously writing to multiple files

Page 24: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 24

Useful System TasksRandom Number Generation

Syntax:$random;

$random(<seed>);

Returns a 32 bit random value

Page 25: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 25

Useful System TasksInitializing Memory from File

Keywords: $readmemb, $readmemh

Used to initialize memory (reg [3:0] mem[0:1023]) Syntax:

$readmemb(“<file_name>”, <memory_name>);

$readmemb(“<file_name>”, <memory_name>, <start_addr>);

$readmemb(“<file_name>”, <memory_name>, <start_addr>, <finish_addr>);

The same syntax for $readmemh

Page 26: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 26

Page 27: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 27

Useful System TasksValue Change Dump (VCD) File

ASCII file containing information on Simulation time Scope and signal definitions Signal value changes

Keywords $dumpvars $dumpfile $dumpon $dumpoff $dumpall

Page 28: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 28

Page 29: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 29

Today Summary

Introduced a number of modeling techniques useful in various applications

Page 30: Digital System Design Verilog ® HDL Useful Modeling Techniques Maziar Goudarzi

2005 Verilog HDL 30

Other Notes

Homework 8 Chapter 9:

All exercises with ModelSim, except for 3 and 5 3 and 5 in paper and pencil Due date: Sunday, Day 11th