+ Post New Thread
Results 1 to 9 of 9
-
4th February 2019, 20:10 #1
- Join Date
- Apr 2013
- Location
- Bangalore
- Posts
- 42
- Helped
- 0 / 0
- Points
- 1,257
- Level
- 8
VHDL Counter FPGA Spartan-6
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;
-
Advertisment
-
4th February 2019, 20:27 #2
- Join Date
- Jun 2010
- Posts
- 6,758
- Helped
- 1976 / 1976
- Points
- 37,095
- Level
- 47
Re: VHDL Counter FPGA Spartan-6
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.
-
6th February 2019, 23:37 #3
- Join Date
- Apr 2018
- Location
- Gdańsk, Poland
- Posts
- 100
- Helped
- 24 / 24
- Points
- 728
- Level
- 5
- Blog Entries
- 3
Re: VHDL Counter FPGA Spartan-6
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.To encourage me to help more, click on "Helpful Post" if you feel that I've helped you.
-
Advertisment
-
7th February 2019, 03:11 #4
- Join Date
- Aug 2016
- Posts
- 243
- Helped
- 37 / 37
- Points
- 1,578
- Level
- 9
Re: VHDL Counter FPGA Spartan-6
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?-------------
--Akanimo.
1 members found this post helpful.
-
Advertisment
-
7th February 2019, 09:13 #5
- Join Date
- Apr 2013
- Location
- Bangalore
- Posts
- 42
- Helped
- 0 / 0
- Points
- 1,257
- Level
- 8
Re: VHDL Counter FPGA Spartan-6
I want the led to blink. I mean ON when count = 250000000-1 is reached and rest of the time OFF
-
7th February 2019, 11:24 #6
Awards:
- Join Date
- Apr 2014
- Posts
- 14,241
- Helped
- 3255 / 3255
- Points
- 69,722
- Level
- 64
Re: VHDL Counter FPGA Spartan-6
Hi,
I want the led to blink. I mean ON when count = 250000000-1 is reached and rest of the time OFF
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.
KlausPlease don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.
1 members found this post helpful.
-
7th February 2019, 13:00 #7
- Join Date
- Aug 2016
- Posts
- 243
- Helped
- 37 / 37
- Points
- 1,578
- Level
- 9
Re: VHDL Counter FPGA Spartan-6
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 by Akanimo; 7th February 2019 at 12:49.
-------------
--Akanimo.
1 members found this post helpful.
-
7th February 2019, 14:10 #8
- Join Date
- Jan 2008
- Location
- Germay
- Posts
- 1,181
- Helped
- 255 / 255
- Points
- 7,950
- Level
- 21
- Blog Entries
- 1
Re: VHDL Counter FPGA Spartan-6
I want the led to blink. I mean ON when count = 250000000-1 is reached and rest of the time OFF
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.FPGA enthusiast!
1 members found this post helpful.
-
Advertisment
-
11th February 2019, 09:02 #9
- Join Date
- Apr 2013
- Location
- Bangalore
- Posts
- 42
- Helped
- 0 / 0
- Points
- 1,257
- Level
- 8
Re: VHDL Counter FPGA Spartan-6
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.
+ Post New Thread
Please login