以下是我写的一个想用按键来控制PWM的占空比的程序,当我把always @( clk48M, key_up, key_down)这条按键功能的语句注释掉时会有正常的波形输出,但是加上后就没有波形了,只有高电平,这是什么原因呢?是语法不正确嘛?请高手指导。。。
module pwm_up_down(
clk48M,
RSTn,
key_up,
key_down,
pwm_out
);
input clk48M;
input RSTn;
input key_up;
input key_down;
output pwm_out;
parameter cnt_top=26'd960000; //F=50hz
reg [25:0] clk_cnt;
reg pwm_out;
reg [25:0] pwm_val=26'd48000; //duty_cycl = 1ms;
always @(negedge clk48M , negedge RSTn)
begin
if(!RSTn)
begin
clk_cnt <= 0;
// pwm_val <= 26'd48000;
end
else
begin
clk_cnt <= clk_cnt + 1;
if(clk_cnt == cnt_top - 1)
begin
clk_cnt <= 0;
end
end
end
always @(pwm_val,clk_cnt,clk48M)
begin
if(clk_cnt < pwm_val)
begin
pwm_out <= 1'b1;
end
else
begin
pwm_out <= 1'b0;
end
end
/*always @( clk48M, key_up, key_down)
begin
if(!key_up)
begin
pwm_val <= pwm_val + 26'd1000;
end
else if(!key_down)
begin
pwm_val <= pwm_val - 26'd1000;
end
else
begin
pwm_val <= pwm_val;
end
end*/
endmodule |