Quantcast
Channel: Altera Forums
Viewing all articles
Browse latest Browse all 19390

DE0-nano - Implementation of a simple flashing led

$
0
0
Hi i have tried to flash a led with 1Hz frequency but could not be able to do it. Can you pls see my code below and advise?
The project compiles fine. I have connected the 50MHz clk to a pll 1/10000 which equals 5KHz. That frequency goes into the module "pwm".
The led output is connected to the first led of the DE0-nano (bit 0).

module pwm(clock, led);
input clock; // wire
output led; reg led;
reg [31:0] ctr=0;
parameter max = 31'd5000;

// When ctr equals max save the value 0 to next_ctr, else increment ctr by one
assign next_ctr = (ctr == max) ? 31'd0 : ctr + 31'd1;
// When ctr equals max save the opposite of led_status to led_status, else save the same value
assign led_status = (ctr == max) ? led_status^1 : led_status;

// Execute the assign expressions on every rising edge of the clock
always @ (posedge clock) begin
led <= led_status; // Change the led status or let it as is
ctr <= next_ctr; // Increment by one or reset to zero when ctr reaches 50M
end
endmodule


I googled it and found more or less similar information. Can you help?

Regards
Manos

Viewing all articles
Browse latest Browse all 19390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>