Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] VHDL Counter FPGA Spartan-6

Status
Not open for further replies.

prakash_kadri

Member level 2
Joined
Apr 11, 2013
Messages
42
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Bangalore
Activity points
1,721
Hello VHDL Experts,

I am new to VHDL. I want to write a simple VHDL program which allows the LED to light up after 5 sec.I am using Spartan-6. The board contains 50 MHz Clock.That means my clock period should be 20 ns. So the value of delay should be equal to (5000000000 ns / 20 ns) = 250000000.
So, when the counter counts from 0 to 249000000 the led lights up.Below is program. But it is not working as i intended it to work.Can you please help to rectify the issue with the program.

----------------------------------------------------------------------------------------------------


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
 
 
entity test123 is
  port (clk,reset : in std_logic; 
        led : out std_logic 
    );
end test123;
 
architecture Behavioral of test123 is
 
signal count : unsigned(27 downto 0) := (others => '0');
 
begin
 
process(clk,reset)
begin
    if(reset = '0') then
        led <= '0';
        count <= (others => '0');
    elsif(rising_edge(clk)) then
          if(count = 250000000-1) then 
            count <= (others => '0');
            led <= '1';
        else
            led <= '0';
            count <= count +1;   --increment counter otherwise.
        end if; 
    end if;
   
end process;
end Behavioral;

 

The led is turned on (or off, of the LEDs are active low) for 20ns, and off for the rest of the second. Maybe you should toggle the led rather than flash it on.
 

Your led will be '1' only for ONE! clk cycle when "count = 250000000-1", otherwise it's '0' for rest of the time (I guess your eyes wouldn't see the effect).
Change the line 26 to toggle led signal: "led <= not led;" and delete the line 28 to do nothing with led when condition "count = 250000000-1" is not met.
 

Hi,

Posts #2 and #3 are actually correct but there is more to it. Your conditions are actually not complete so you may still not get what you want from the solutions offered.

Here is an additional info that's necessary. How do you want the LED to behave after it has been turned ON? Do you Do you want it to remain ON until RESET or at loss of power? Do you want it to go OFF after some time? Or does it not matter what follows?
 
I want the led to blink. I mean ON when count = 250000000-1 is reached and rest of the time OFF
 

Hi,

I want the led to blink. I mean ON when count = 250000000-1 is reached and rest of the time OFF
Are you sure?
LED OFF for 4.99999998s
LED ON for 0.00000002s
LED OFF for 4.99999998s
LED ON for 0.00000002s
and so on..

How do you think you can detect the "ON" for a very short time of 20ns?
Surely not with your eyes.

Klaus
 
Just like everybody has told you, you cannot detect that the LED is blinking. It is blinking though but you won't notice it.

You can go with post #3 but the LED will be toggled after every 5 seconds. If that time is too long for the LED to stay ON, then you can edit Line 27 to be:

elsif count = (50000000-1) then

Also insert between lines 29 and 30:

else count <= count+1;

This will make the LED to stay ON for 1 second and OFF for 4 seconds. But it will light up the first time after 5 seconds. If you need another ON time duration, you can figure out the value that would make that happen and use that in place of the 50000000 that would now be in line 27.

- - - Updated - - -

Add:

If you want OFF time to be 5 seconds and ON time to be x seconds then you have to increase your LED cycle period from 5 seconds to (5+x) seconds.
 
Last edited:
I want the led to blink. I mean ON when count = 250000000-1 is reached and rest of the time OFF
Make it blink at a rate of 1Hz, your eye will be able to detect that.
For 1 sec turn OFF the LED and for the next 1 sec, turn ON the LED.
You have a clock of 50 MHz, the counter value calc for I leave it to you as an exercise.
 
Hi All,

Thank you very much for your valuable inputs. Now the program works as I wanted.
BTW I am working on a hobby robot where I am using 6 servos , so this exercise I did to understand how to create delay between the servos.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top