Skip to content

Commit b7f3bee

Browse files
author
Konstantin Pavlov
committed
Added SystemVerilog variant of main_tb
1 parent f838698 commit b7f3bee

File tree

3 files changed

+180
-86
lines changed

3 files changed

+180
-86
lines changed

Main_tb.v

Lines changed: 0 additions & 86 deletions
This file was deleted.

main_tb.sv

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//------------------------------------------------------------------------------
2+
// main_tb.sv
3+
// Konstantin Pavlov, pavlovconst@gmail.com
4+
//------------------------------------------------------------------------------
5+
6+
// INFO ------------------------------------------------------------------------
7+
// Testbench template with basic clocking, reset and random stimulus signals
8+
9+
`timescale 1ns / 1ps
10+
11+
module main_tb();
12+
13+
logic clk200;
14+
initial begin
15+
#0 clk200 = 1;
16+
forever
17+
#2.5 clk200 = ~clk200;
18+
end
19+
20+
logic rst;
21+
initial begin
22+
#10.2 rst = 1;
23+
#5 rst = 0;
24+
//#10000;
25+
forever begin
26+
#9985 rst = ~rst;
27+
#5 rst = ~rst;
28+
end
29+
end
30+
31+
logic nrst;
32+
assign nrst = ~rst;
33+
34+
logic rst_once;
35+
initial begin // initializing non-X data before PLL starts
36+
#10.2 rst_once = 1;
37+
#5 rst_once = 0;
38+
end
39+
initial begin
40+
#510.2 rst_once = 1; // PLL starts at 500ns, clock appears, so doing the reset for modules
41+
#5 rst_once = 0;
42+
end
43+
44+
logic nrst_once;
45+
assign nrst_once = ~rst_once;
46+
47+
logic [31:0] DerivedClocks;
48+
ClkDivider #(
49+
.WIDTH( 32 )
50+
) CD1 (
51+
.clk( clk200 ),
52+
.nrst( nrst_once ),
53+
.out( DerivedClocks[31:0] )
54+
);
55+
56+
logic [31:0] E_DerivedClocks;
57+
EdgeDetect #(
58+
.WIDTH( 32 )
59+
) ED1 (
60+
.clk( clk200 ),
61+
.nrst( nrst_once ),
62+
.in( DerivedClocks[31:0] ),
63+
.rising( E_DerivedClocks[31:0] ),
64+
.falling( ),
65+
.both( )
66+
);
67+
68+
logic [15:0] RandomNumber1;
69+
c_rand RNG1 (
70+
.clk( clk200 ),
71+
.rst( rst_once ),
72+
.reseed( 1'b0 ),
73+
.seed_val( DerivedClocks[31:0] ),
74+
.out( RandomNumber1[15:0] )
75+
);
76+
77+
logic start;
78+
initial begin
79+
#0 start = 1'b0;
80+
#100.2 start = 1'b1;
81+
#5 start = 1'b0;
82+
end
83+
84+
// Module under test ==========================================================
85+
86+
wire out1,out2;
87+
Main M ( // module under test
88+
clk200,~clk200,
89+
rst_once,
90+
out1,out2 // for compiler not to remove logic
91+
);
92+
93+
endmodule

main_tb.v

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//------------------------------------------------------------------------------
2+
// main_tb.v
3+
// Konstantin Pavlov, pavlovconst@gmail.com
4+
//------------------------------------------------------------------------------
5+
6+
// INFO ------------------------------------------------------------------------
7+
// Testbench template with basic clocking, reset and random stimulus signals
8+
// See main_tb.sv file for SystemVerilog version of this module
9+
10+
`timescale 1ns / 1ps
11+
12+
module main_tb();
13+
14+
reg clk200;
15+
initial begin
16+
#0 clk200 = 1;
17+
forever
18+
19+
end
20+
21+
reg rst;
22+
initial begin
23+
#10.2 rst = 1;
24+
#5 rst = 0;
25+
//#10000;
26+
forever begin
27+
#9985 rst = ~rst;
28+
#5 rst = ~rst;
29+
end
30+
end
31+
wire nrst = ~rst;
32+
33+
reg rst_once;
34+
initial begin // initializing non-X data before PLL starts
35+
#10.2 rst_once = 1;
36+
#5 rst_once = 0;
37+
end
38+
initial begin
39+
#510.2 rst_once = 1; // PLL starts at 500ns, clock appears, so doing the reset for modules
40+
#5 rst_once = 0;
41+
end
42+
wire nrst_once = ~rst_once;
43+
44+
wire [31:0] DerivedClocks;
45+
ClkDivider CD1 (
46+
.clk( clk200 ),
47+
.nrst( nrst_once ),
48+
.out( DerivedClocks[31:0] )
49+
);
50+
defparam CD1.WIDTH = 32;
51+
52+
wire [31:0] E_DerivedClocks;
53+
EdgeDetect ED1 (
54+
.clk( clk200 ),
55+
.nrst( nrst_once ),
56+
.in( DerivedClocks[31:0] ),
57+
.rising( E_DerivedClocks[31:0] ),
58+
.falling( ),
59+
.both( )
60+
);
61+
defparam ED1.WIDTH = 32;
62+
63+
wire [15:0] RandomNumber1;
64+
c_rand RNG1 (
65+
.clk( clk200 ),
66+
.rst( rst_once ),
67+
.reseed( 1'b0 ),
68+
.seed_val( DerivedClocks[31:0] ),
69+
.out( RandomNumber1[15:0] )
70+
);
71+
72+
reg start;
73+
initial begin
74+
#100.2 start = 1;
75+
#5 start = 0;
76+
end
77+
78+
// Module under test ==========================================================
79+
80+
wire out1,out2;
81+
Main M ( // module under test
82+
clk200,~clk200,
83+
rst_once,
84+
out1,out2 // for compiler not to remove logic
85+
);
86+
87+
endmodule

0 commit comments

Comments
 (0)