-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpwm_test.sv
More file actions
45 lines (39 loc) · 749 Bytes
/
Copy pathpwm_test.sv
File metadata and controls
45 lines (39 loc) · 749 Bytes
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
module pwm_test(RAW_CLK, RST, KEY1, ESC, LED_PWM);
input logic RAW_CLK;
input logic RST;
input logic KEY1;
output logic ESC = 0;
output logic LED_PWM = 0;
logic clk = 0;
logic [31:0] clk_ctr = 31'b0;
logic [63:0] micros = 63'b0;
logic [63:0] t0 = 63'b0;
wire [63:0] dt = micros - t0;
always @(posedge clk) begin
if(~RST) begin
ESC <= 0;
micros <= 63'b0;
t0 <= 63'b0;
end else begin
if(dt > 2083) begin
t0 <= micros;
ESC <= 1;
LED_PWM <= 1;
end else begin
if(dt > 1000 + 1000 * KEY1) begin
ESC <= 0;
LED_PWM <= 0;
end
end
micros <= micros + 1;
end
end
always @(posedge RAW_CLK) begin
if(clk_ctr >= 24) begin
clk <= ~clk;
clk_ctr <= 31'b0;
end else begin
clk_ctr <= clk_ctr + 1;
end
end
endmodule