verilong的呼吸灯程序,有些看不明白,请大家帮忙给解释下
别人的verilong的呼吸灯程序,有些看不明白,请大家帮忙给解释下做"///////////"标识的地方的程序,谢谢大家。module breathing_led(
input wire clk,
input wire rst_n,
output reg LED
);
reg counter;
reg PWM_adjust;
reg PWM_width;
always @ (posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
counter <= 0;
LED <= 0;
LED <= 0;
LED <= 0;
LED <= 0;
end
else
begin
counter <= counter + 1; // 时钟上升沿到来就自加一
PWM_width <= PWM_width + PWM_adjust; ///////////
if(counter) ///////////
begin
PWM_adjust <=counter; ///////////
end
else
begin
PWM_adjust <= ~counter; ///////////
end
LED <= PWM_width; ///////////
LED <= PWM_width;
LED <= PWM_width;
LED <= PWM_width;
end
end
endmodule
自己分析了一下,发现是根据counter的多位移位进行来调整占空比的。希望多多交流~{:smile:} 人对光和声音的强度感应为对数曲线,占空比移位对应到人眼就是线性增减
页:
[1]