360 likes | 871 Views
Digital System Design. Verilog ® HDL Useful Modeling Techniques. Maziar Goudarzi. Today Program. Procedural Continuous Assignment Overriding Parameters Conditional Compilation and Execution Useful System Tasks. Procedural Continuous Assignment. Useful Modeling Techniques.
E N D
Digital System Design Verilog® HDLUseful Modeling Techniques Maziar Goudarzi
Today Program • Procedural Continuous Assignment • Overriding Parameters • Conditional Compilation and Execution • Useful System Tasks Verilog HDL
Procedural Continuous Assignment Useful Modeling Techniques
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 Verilog HDL
Procedural Continuous Assignment (cont’d) • assign/deassign • Keywords • assign: 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. Verilog HDL
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 Verilog HDL
force/release on reg variables Verilog HDL
force/release on nets • Net value immediately returns to its normal assigned value when released Verilog HDL
Overriding Parameters Useful Modeling Techniques
Overriding Parameters • Two methods • defparam statement • Module instance parameter value assignment • defparam statement • Keyword: defparam • Syntax: defparam <parameter_hierarchical_name>=<value>; Verilog HDL
Overriding Parameters (cont’d) • Module instance parameter values • Parameters are overridden when the module is instantiated • Syntax: <module_name> #(<param_vals>) <instance_name>; Verilog HDL
Example with multiple parameters Verilog HDL
Conditional Compilation and Execution Useful Modeling Techniques
Conditional Compilation • Usage: • To compile some part of code under certain conditions • Keywords: • ‘ifdef, `else, `endif • ‘define to define the flag Verilog HDL
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> ) Verilog HDL
Useful System Tasks Useful Modeling Techniques
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) Verilog HDL
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>); Verilog HDL
Example: Simultaneously writing to multiple files Verilog HDL
Useful System TasksRandom Number Generation • Syntax: $random; $random(<seed>); • Returns a 32 bit random value Verilog HDL
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 Verilog HDL
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 Verilog HDL
Today Summary • Introduced a number of modeling techniques useful in various applications Verilog HDL
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 Verilog HDL