add pwm generator
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user