-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsimulate_tb.v
100 lines (85 loc) · 2.3 KB
/
simulate_tb.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
`timescale 100ns / 10ns
module testbench;
reg clk;
always #5 clk = (clk === 1'b0);
wire led_r, led_g, led_b, i_one_wire, o_one_wire;
reg r_rst;
reg i_one_wire_reg;
// Instantiate the test bench
sim_top uut (
.i_clk(clk),
.i_rst(r_rst),
.O_LED_R(led_r),
.O_LED_G(led_g),
.O_LED_B(led_b),
.I_ONE_WIRE(i_one_wire),
.O_ONE_WIRE(o_one_wire)
);
reg [4095:0] vcdfile;
initial begin
$timeformat(3, 2, " ns", 20);
if ($value$plusargs("vcd=%s", vcdfile)) begin
$dumpfile(vcdfile);
$dumpvars(0, testbench);
end
end
// Generate the reset
initial begin
r_rst = 1'b1;
repeat (10) @(posedge clk);
r_rst = 1'b0;
end
// One wire slave mock up
initial begin
i_one_wire_reg = 1'b1;
repeat (500) @(posedge clk);
i_one_wire_reg = 1'b0;
repeat (200) @(posedge clk);
i_one_wire_reg = 1'b1;
end
// One wire slave mock up
initial begin
i_one_wire_reg = 1'b1;
repeat (21500) @(posedge clk);
i_one_wire_reg = 1'b0;
repeat (200) @(posedge clk);
i_one_wire_reg = 1'b1;
end
assign i_one_wire = i_one_wire_reg;
// Check if the ds18b20 is detected correctly
initial begin
// Check the green LED at 11000 steps (cycle one)
repeat (11000) @(posedge clk);
$display("DS18B20 Should not be detected at run 1");
if (led_g == 1'b1) begin
$display("DS18B20 not detected at run 1: FAIL");
$finish;
end else begin
$display("DS18B20 detected at run 1: OK");
end
// Check the green LED at 32000 steps (run two)
repeat (21000) @(posedge clk);
$display("DS18B20 Should not be detected at run 2");
if (led_g == 1'b1) begin
$display("DS18B20 not detected at run 2: FAIL");
$finish;
end else begin
$display("DS18B20 detected at run 2: OK");
end
// Check the red LED at 53000 steps (run two)
repeat (21000) @(posedge clk);
$display("DS18B20 Should not be detected at run 3");
if (led_r == 1'b1) begin
$display("DS18B20 detected at run 3: FAIL");
$finish;
end else begin
$display("DS18B20 not detected at run 3: OK");
end
end
// End the simulation at 200_000 cycles
initial begin
repeat (100000) @(posedge clk);
$display("SUCCESS: Simulation run for 100000 cycles.");
$finish;
end
endmodule