module pwm4_basic(clk,rst,duty,pwm_out);
input clk;
input rst;
input [3:0]duty;
output reg pwm_out;
reg [3:0]counter=0;
reg [4:0]cnt=0;
always@(posedge clk)begin
if (rst)begin
pwm_out<=0;
counter<=0;
cnt<=0;
end
else begin
counter<=counter+1;
if(counter<duty)begin
pwm_out<=1;
counter<=counter+1; end
else pwm_out<=0;
if(counter==5'd16)begin
counter<=0;
end
end
end
endmodule