/*Write your code here*/
module pwm4_basic(
input wire clk,
input wire rst,
input wire [3:0] duty,
output reg [3:0] pwm_out
);
reg [3:0] counter;
wire [3:0] next_counter, pwm_out_next;
always @(posedge clk, posedge rst)begin
if(rst)begin
counter <=0;
pwm_out <=0;
end
else begin
counter <= next_counter;
pwm_out <= pwm_out_next;
end
end
assign next_counter = counter + 4'b0001;
assign pwm_out_next = counter < duty;
endmodule