就开关3能用--。其他都出不来
module pwm_top(
input clk,rst,
input sw1,sw2,sw3,sw4,sw5,
output pwm
);
reg [15:0]cnt;
reg [5:0]duty;
reg [15:0]count;
reg clk_div;
reg pwm;
always@(posedge clk or posedge rst)
if(rst)begin
count<=0;clk_div<=0;
end
else if(count==50000)begin
clk_div<=~clk_div;count<=0;
end
else count<=count+1;
always@(posedge clk_div or posedge rst)
if(rst)begin
pwm<=1;
duty<=0;
end
else begin
if(duty<=20)
duty<=0;
else
duty<=duty+1;
if(sw1)begin
if(duty<4)
pwm<=0;
else
pwm<=1;
end
else if(sw2)begin
if(duty<8)
pwm<=0;
else
pwm<=1;
end
else if(sw3)
pwm<=~pwm;
else if(sw4)begin
if(duty<16)
pwm<=0;
else
pwm<=1;
end
else if(sw5)
pwm<=0;
else
pwm<=1;
end
endmodule
此帖出自
小平头技术问答
哦哦哦 我比较少接触论坛=.=下次会注意的
一周热门 更多>