Community
cancel
Showing results for 
Search instead for 
Did you mean: 
imarz1
Novice
573 Views

I have simple code question

Hi:

I am very beginner. I wrote very simple code for DE10-Nano board to turn on one LED, but it is not working. Maybe someone could help:

module LED (

CLK_50,

LED1

);

input CLK_50;

output reg LED1;

integer counter=0;

 

always @*

begin

//LED1 <= 0;

counter <= counter + 1;

if(counter == 200000)

begin

LED1 <= 1;

//counter <= 0;

end

if(counter == 400000)

begin

LED1 <= 0;

counter <= 0;

end

end

endmodule

 

*******************************

After programming, LED1 never ever turn ON. I tried many different values in Counter, and still nothing.

My understanding is that when Counter is between 200000 - 400000, then LED1 will turn ON.

 

Thanks in advance.

0 Kudos
3 Replies
AnandRaj_S_Intel
Employee
63 Views

Hi,

 

  1. Check your Pin assignments.
  2. Check you code in modelsim (@* includes all the inputs used in block) or debug using signal tap.
  3. You have used smaller counter value, the led is toggling at 125 Hz because of which we can't see it.
  4. Try to toggle the led at less than 40 Hz.

 

Or just use switch and led to start with.

module LED ( input SW, output LED );   assign LED= SW;   endmodule

 

Let me know if this has helped resolve the issue you are facing or if you need any further assistance.

 

Regards

Anand

imarz1
Novice
63 Views

Hi:

I can turn ON LED by: LED1 <= 1;

Also, the CLK_50 is set to pin_V11.

So, probably it is not pin assignment issue.

 

The problem seems to be when creating time delay before turning ON the LED... I am unable to create any time delay.

For example the following delays did not work:

1- if(counter == 200000)

2- for (i = 0; i < 500; i = i +1) : Here i found out I can't have more than 500 iteration in FOR loop ? Not sure if this is verilog restriction or Quartus issue.

3- repeat(500) : Here too, I can't have more than 500 iteration ? Same, not sure if this is verilog restriction or Quartus issue.

In all these three cases the LED turns ON immediately. The delays were nothing, even though I looped many "repeat(500)" within the For loop.

Remember, I am very beginner, so I might have made a rookie mistake somewhere...

 

Thanks.

 

sstrell
Honored Contributor II
63 Views

You haven't set up your always block correctly. Since you're creating a counter, it should probably be:

 

always @ (posedge CLK_50)

 

Without a clock, the way your code is written, nothing will happen (the counter will never increment).

 

#iwork4intel

Reply