-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPWM_Even_Clk.v
59 lines (42 loc) · 1.26 KB
/
PWM_Even_Clk.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 05/22/2022 02:04:19 PM
// Design Name:
// Module Name: PWM
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
//PWM generated using Even clock divider
module PWM_EVEN_CLK #( channel_width = 5)(
input rst,
input clk_even,
output [channel_width - 1 : 0] pwm_even_clk
);
reg [7:0] counter = 0;
always @(posedge clk_even)
begin
counter <= counter + 1;
end
// Duty Cycle = counter / total value stored in the counter
// counter = (Duty Cycle * total value stored) /100
// = (25*256)/100
// = 64
// As per the need of Duty cycle the value of counter can be adjusted
assign pwm_even_clk[0] = 0; // 0% Duty Cycle
assign pwm_even_clk[1] = (counter < 64)? 1:0; // 25% Duty Cycle
assign pwm_even_clk[2] = (counter < 128)? 1:0; // 50% Duty Cycle
assign pwm_even_clk[3] = (counter <192)? 1:0; // 75% Duty Cycle
assign pwm_even_clk[4] = 1; // 100% Duty cycle
endmodule