-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtb_PWM_gen.v
86 lines (82 loc) · 1.74 KB
/
tb_PWM_gen.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
`timescale 1ns / 1ps
module tb_PWM_gen;
// Inputs
reg clk;
reg increase_duty;
reg decrease_duty;
reg reset;
// Outputs
wire PWM_OUT;
//wire [3:0] dc,db,cnt;
// Instantiate the PWM Generator with variable duty cycle in Verilog
PWM_gen PWM_Generator_Unit(
.clk(clk),
.increase_duty(increase_duty),
.decrease_duty(decrease_duty),
.reset(reset),
.PWM_OUT(PWM_OUT)
//.dc(dc),.db(db),.cnt(cnt)
);
// Create 100Mhz clock
initial
begin
//for creating vcd waveform file to view in gtkwave
$dumpfile ("tb_PWM_gen.vcd"); //by default vcd
$dumpvars(0, tb_PWM_gen);
end
initial begin
clk = 0;
reset=0;
increase_duty = 0;
decrease_duty = 0;
forever #5 clk = ~clk;
end
initial begin
#5 reset=1;
#5 reset =0;
#100;
increase_duty = 1;
#100;// increase duty cycle by 10%
increase_duty = 0;
#100;
increase_duty = 1;
#100;// increase duty cycle by 10%
increase_duty = 0;
#100;
increase_duty = 1;
#100;// increase duty cycle by 10%
increase_duty = 0;
#100;
increase_duty = 1;
#100;// increase duty cycle by 10%
increase_duty = 0;
#100;
increase_duty = 1;
#100;// increase duty cycle by 10%
increase_duty = 0;
#200 reset =1;
#5 reset = 0;
decrease_duty = 1;
#100;//decrease duty cycle by 10%
decrease_duty = 0;
#100;
decrease_duty = 1;
#100;//decrease duty cycle by 10%
decrease_duty = 0;
#100;
decrease_duty = 1;
#100;//decrease duty cycle by 10%
decrease_duty = 0;
#100;
decrease_duty = 1;
#100;//decrease duty cycle by 10%
decrease_duty = 0;
#100;
decrease_duty = 1;
#100;//decrease duty cycle by 10%
decrease_duty = 0;
#200 reset = 1;
#5 reset = 0;
end
initial #2500 $finish;
endmodule