LED Blink with PWM (heart beat LED)
LEDの点滅をPWMで行ってみます。ハートビート用のLEDです。
クロック(clk_in)には50MHzのクロックを入力します。
blink_led_pwm.v
module blink_led_pwm(clk_in, reset_n, led_out);
input clk_in;
output led_out;
reg [25:0] count;
always @(posedge clk or negedge reset_n)
begin
if (!reset_n)
begin
count = 0;
end
else
begin
count<=count+1;
end
end
wire [6:0] pwm_input = count[25] ? count[24:18] : ~count[24:18];
reg [7:0] pwm;
always @(posedge clk)
begin
pwm <= pwm[6:0]+pwm_input;
end
assign led_out = pwm[7];
endmodule