-
Notifications
You must be signed in to change notification settings - Fork 0
/
PWM12.sv
83 lines (52 loc) · 793 Bytes
/
PWM12.sv
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
module PWM12(clk,rst_n,duty,PWM1,PWM2);
input clk, rst_n;
input [11:0] duty;
output reg PWM1, PWM2;
reg [11:0] cnt;
localparam NONOVERLAP = 12'h02C;
logic S1,S2,R1,R2;
always_comb begin
S1 = 0;
R1 = 0;
S2 = 0;
R2 = 0;
if(cnt >= NONOVERLAP)
S1 = 1;
if(cnt >= (duty+NONOVERLAP))
S2 = 1;
if(cnt >= duty)
R1 = 1;
if(&cnt)
R2 = 1;
end
always_ff @(posedge clk, negedge rst_n) begin
if(!rst_n)
PWM1 <= 1'b0;
else begin
if(R1)
PWM1 <= 1'b0;
else if(S1)
PWM1 <= 1'b1;
else
PWM1 <= PWM1;
end
end
always_ff @(posedge clk, negedge rst_n) begin
if(!rst_n)
PWM2 <= 1'b0;
else begin
if(R2)
PWM2 <= 1'b0;
else if(S2)
PWM2 <= 1'b1;
else
PWM2 <= PWM2;
end
end
always_ff @(posedge clk , negedge rst_n) begin
if(!rst_n)
cnt = '0;
else
cnt = cnt + 1;
end
endmodule