/*Write your code here*/
module pwm4_basic(
input clk,
input rst,
input [3:0] duty,
output reg pwm_out
);
reg [4:0] counter;
always @(posedge clk) begin
if(rst) begin
pwm_out <= 1'b0;
counter <= 4'd0;
end else begin
if(counter < duty) begin
pwm_out <= 1'b1;
end else begin
pwm_out <= 1'b0;
end
if(counter == 4'd15) begin
counter <= 4'd0;
end else begin
counter <= counter + 1'b1;
end
end
end
endmodule