|
<< Click to Display Table of Contents >> 4.3 Direct Signal Code |
![]() ![]()
|
The Verilog and VHDL tabs in the Signal Properties dialog allow you to view and edit the generated code for a specific signal. Also when moving diagram directories around there is an environment variable $(DiagramDir) that will tell the diagram to look for models in the directory where the current diagram is stored.
To View or Edit the Simulated Signals Code:
|
|
|
|
|
|
|
Tips on writing direct code:
| 1. | All the HDL code is placed inside a module. This places one important restriction on the HDL code: it cannot contain an HDL module declaration (i.e. you cannot define a new type of component inside a signal's direct HDL code block). You CAN create an instance of an HDL module, however, as long as the module is declared somewhere else (e.g. in wavelib.v). The advanced simulation tutorial covers this in more detail. |
| 2. | Signals are always treated as wires during Verilog code generation. This makes it easy to write simple continuous assignment statements. This also means that if you want to control the signal state using behavioral code, you will need to create a reg as a intermediate variable and then assign the SynaptiCAD signal to the value of the intermediate reg. This is because the values of wire (nets) cannot be set inside a behavioral (initial or always) block. For example, direct behavioral code for a signal called SIG0 that inverts whenever CLK changes state would be written as: |
reg tempSIG0; //temporary reg
always @(CLK)
begin
tempSIG0 = !tempSIG0; //invert temporary whenever CLK changes
end
assign SIG0 = tempSIG0; //set WaveFormer signal to value of tempSIG0
Notice that you do not have to declare the WaveFormer signal SIG0 because WaveFormer automatically creates it. However, you do have to declare the temporary reg tempSIG0 because WaveFormer doesn't know anything about it.
Pre-Defined Environment Variable for Diagram Directory
There is a pre-defined environment variable that contains the directory where the currently simulating diagram is located. You can use this variable to make the diagram simulator search for library files in the diagram directory.
|
;$(DiagramDir)
|