-
Notifications
You must be signed in to change notification settings - Fork 0
/
irrigation_system_tb.v
76 lines (66 loc) · 1.61 KB
/
irrigation_system_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
module irrigation_system_tb;
reg tb_clk;
reg tb_reset;
reg [3:0] tb_sensor;
wire tb_pump;
parameter THRESHOLD = 4'b0100;
parameter DELAY = 20;
reg [7:0] counter;
// Instantiate the module under test
irrigation_system dut (
.clk(tb_clk),
.reset(tb_reset),
.sensor(tb_sensor),
.pump(tb_pump)
);
// Clock generation
always begin
tb_clk = 0;
#5;
tb_clk = 1;
#5;
end
initial begin
// Initialize inputs
#10 tb_reset = 0;
// Test case 1: Soil moisture is low initially
#20 begin
tb_reset = 1;
tb_sensor = 4'b0010; // Set soil moisture below the threshold
if (tb_sensor < THRESHOLD) begin
#50;
tb_sensor = 4'b0101; // Set soil moisture above the threshold
#20;
if (tb_pump == 0)
$display("Test case 1 passed");
else
$display("Test case 1 failed");
end
end
// Test case 2: Soil moisture is high initially
#20 begin
tb_sensor = 4'b1100; // Set soil moisture above the threshold
if (tb_sensor >= THRESHOLD) begin
#50;
tb_sensor = 4'b0001; // Set soil moisture below the threshold
if (tb_pump == 0 && counter == 0)
$display("Test case 2 failed");
else
$display("Test case 2 passed");
end
end
// Test case 3
#20 begin
tb_sensor = 4'b0001;
#200;
tb_sensor = 4'b0010; //waiting
if (tb_pump == 0)
$display("Test case 3 passed");
else begin
$display("Test case 3 failed");
end
end
#100;
$finish; // End the simulation
end
endmodule