how to simulate behavioral verilog code using …

19
HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING NCLAUNCH This tutorial explains how to simulate a behavioral code using NCLaunch. In order to do so, let’s consider the verilog codes below. CNT_16 Module: 16 bit up counter with asynchronous active-low reset `timescale 1ns/1ps module CNT_16(CLK, RSTB, OUT); input CLK, RSTB; output [15:0] OUT; reg [15:0] OUT; always@(posedge CLK or negedge RSTB) begin if(!RSTB) begin OUT <= 0; end else begin OUT <= OUT + 1; end end endmodule CMP_16 Module: Comparator which compares the 16 bit input with 50. `timescale 1ns/1ps module CMP_16(IN, OUT); input [15:0] IN; output OUT; reg OUT; always@(IN) begin if(IN <= 50) begin

Upload: others

Post on 30-Apr-2022

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING

NCLAUNCH

This tutorial explains how to simulate a behavioral code using NCLaunch. In order to do so,

let’s consider the verilog codes below.

CNT_16 Module:

16 bit up counter with asynchronous active-low reset

`timescale 1ns/1ps module CNT_16(CLK, RSTB, OUT); input CLK, RSTB; output [15:0] OUT; reg [15:0] OUT; always@(posedge CLK or negedge RSTB) begin if(!RSTB) begin OUT <= 0; end else begin OUT <= OUT + 1; end end endmodule

CMP_16 Module:

Comparator which compares the 16 bit input with 50.

`timescale 1ns/1ps module CMP_16(IN, OUT); input [15:0] IN; output OUT; reg OUT; always@(IN) begin if(IN <= 50) begin

Page 2: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

OUT = 0; end else begin OUT = 1; end end endmodule

TOP Module:

The top module which connects both. The resulting design makes OUT=1 after 50 clock

cycles.

`timescale 1ns/1ps module TOP(CLK, RSTB, OUT); input CLK, RSTB; output OUT; wire [15:0] OUT_16; CMP_16 U1(OUT_16, OUT); CNT_16 U2(CLK, RSTB, OUT_16); endmodule

TEST_TOP Module:

Testbench module to test the top module.

`timescale 1ns/1ps module TEST_TOP; reg CLK, RSTB; wire OUT; initial begin RSTB = 0; CLK = 0; #3 RSTB = 1; #10000 $finish; end always #5 CLK = ~CLK; TOP U1(CLK, RSTB, OUT);

Page 3: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

endmodule

To start behavioral simulation, let’s make a new folder.

Then let’s copy all Verilog files to newly created folder.

Page 4: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

Launch NCLaunch program with nclaunch –new command. If we had run a simulation in the

folder before that we want to go back to, we should simply use nclaunch command.

Let’s choose Multiple Step for step by step compilation, elaboration and simulation. Single

Step makes all these three in one step.

Page 5: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

In order to initialize NCLaunch, we need a cds.lib file. Let’s click on Create cds.lib File

And save newly created cds.lib file into our simulation folder.

Page 6: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

When asked for which libraries to include, select Don’t include any libraries for verilog

designs.

Now our cds.lib is created. Let’s click OK

Page 7: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

The NCLaunch window looks like this. Left panel is the directory which includes the verilog

files. Right side is the design hierarchy. worklib is the library which includes our compiled

designs and Snapshots is the folder which includes our elaborated testbenches.

Let’s select the verilog files from the left panel and click Launch Verilog Compiler icon.

Alternatively we can double click on each file to compile.

Page 8: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

If there are no errors, the compiled designs are shown under the worklib.

Let’s click on testbench module TEST_TOP and click Launch Elaborator icon to elaborate

the testbench.

Page 9: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

Elaborated testbench module is shown under Snapshots. Let’s select that module and click

Launch Simulator icon.

The simulator program SimVision opens. From the Design Browser window, let’s select the

design to see the waveform names.

Page 10: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

Let’s select waveforms then click Send to Waveform window icon.

Now we can see the waveform names in the left pane. Let’s click Run the simulation icon.

Page 11: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

Let’s click Zoom Out icon to see more of our waveforms.

Let’s check whether the value of the counter is 50 when OUT goes high. In order to add the

output of the counter to the waveform window, let’s click on Browse the design hierarchy

icon.

Page 12: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

The OUT_16 wire of TOP module would to the trick, so let’s find and select the new

waveform to be added. Just clicking on the wire name will add it to the waveform window.

Next, let’s click on Collapse the Design Browser to get rid of Design Browser.

Page 13: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

As we can see, the newly added waveform is empty. In order to see the waveform, we should

run the simulation again. In order to do so, let’s click on Reset the simulation icon

Now let’s click on the Run the simulation icon once again.

Page 14: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

Then zoom out once again to see more.

Since we humans can understand decimal digits easier, let’s right click on the cursor column

and select Decimal in Radix/Mnemonic tab.

Page 15: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

As we can see, the OUT goes high when the counter hits 50, so the design works as expected.

Now let’s change the design a little bit. Let’s return to NCLaunch window and right click on

CMP_16 submodule, then select Edit.

Page 16: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

Let’s change the compared value from 50 to 40.

After we save the file and exit from the editor, we can see that icons of some designs in the

right panel have a little clock, which means that they are outdated. In order to update them,

let’s right click on the elaborated testbench and select Update.

Page 17: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

Then click OK

All design files are now updated. As we can see, updating elaborated testbench is enough to

update all submodules.

Page 18: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

To simulate our new design, we can close the SimVision and launch it again from NCLaunch.

But if we do that, out waveform selections and waveform configurations such as selecting

decimal radix of OUT_16 will be lost. So, in order to make things faster, let’s click on

Reinvoke Simulator from the Simulation menu of SimVision.

Let’s click Yes to reinvoke simulator

Page 19: HOW TO SIMULATE BEHAVIORAL VERILOG CODE USING …

Let’s start the simulation again by clicking on Run the simulation icon.

As we can see, the new design works as expected. The OUT goes high when the counter hits

40.