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