FPGA, SoC, And CPLD Boards And Kits
FPGA Evaluation and Development Kits
5915 Discussions

DE0-nano - Implementation of a simple flashing led

Altera_Forum
Honored Contributor II
1,500 Views

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
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
477 Views

Hi everyone,  

 

I solved the issue.  

 

module test(clock, led); 

input clock; // wire 

output led; reg led; 

reg [31:0] ctr=0; 

parameter max = 5000; 

 

 

// Execute the assign expressions on every rising edge of the clock 

always @ (posedge clock) begin 

ctr <= (ctr == max) ? 0 : ctr + 1; 

led <= (ctr == max) ? led^1 : led; 

end 

endmodule 

 

 

Regards 

Manos
0 Kudos
Reply