add pwm generator

This commit is contained in:
Elie Deletang
2026-11-29 11:24:30 +01:00
parent d2225bdb93
commit 59781bcbc0
6 changed files with 1234 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
module pwm_gen #(
parameter int WIDTH = 8
) (
input logic clk,
input logic rst,
input logic en,
input logic [WIDTH-1:0] duty,
output logic pwm_out
);
logic [WIDTH-1:0] count;
always_ff @(posedge clk) begin
if (rst) begin
count <= '0;
end else if(en) begin
count <= count + 1'b1;
end
end
always_comb begin
if (!en) begin
pwm_out = 1'b0;
end else if(duty == '1) begin
pwm_out = 1'b1;
end else begin
pwm_out <= (count < duty);
end
end
endmodule