+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Member level 1
    Points: 1,223, Level: 7

    Join Date
    Apr 2013
    Location
    Bangalore
    Posts
    36
    Helped
    0 / 0
    Points
    1,223
    Level
    7

    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;

  2. #2
    Advanced Member level 5
    Points: 37,078, Level: 47
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,755
    Helped
    1974 / 1974
    Points
    37,078
    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.



    •   AltAdvertisment

        
       

  3. #3
    Full Member level 1
    Points: 718, Level: 5
    Achievements:
    Created Blog entry

    Join Date
    Apr 2018
    Location
    Gdańsk, Poland
    Posts
    99
    Helped
    24 / 24
    Points
    718
    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.



    •   AltAdvertisment

        
       

  4. #4
    Full Member level 5
    Points: 1,564, Level: 9

    Join Date
    Aug 2016
    Posts
    240
    Helped
    37 / 37
    Points
    1,564
    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.

    •   AltAdvertisment

        
       

  5. #5
    Member level 1
    Points: 1,223, Level: 7

    Join Date
    Apr 2013
    Location
    Bangalore
    Posts
    36
    Helped
    0 / 0
    Points
    1,223
    Level
    7

    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



  6. #6
    Super Moderator
    Points: 69,422, Level: 64
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    14,177
    Helped
    3237 / 3237
    Points
    69,422
    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
    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
    Please 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.

  7. #7
    Full Member level 5
    Points: 1,564, Level: 9

    Join Date
    Aug 2016
    Posts
    240
    Helped
    37 / 37
    Points
    1,564
    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.

  8. #8
    Advanced Member level 4
    Points: 7,936, Level: 21
    Achievements:
    7 years registered Created Blog entry
    dpaul's Avatar
    Join Date
    Jan 2008
    Location
    Germay
    Posts
    1,178
    Helped
    255 / 255
    Points
    7,936
    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
    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.
    FPGA enthusiast!


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  9. #9
    Member level 1
    Points: 1,223, Level: 7

    Join Date
    Apr 2013
    Location
    Bangalore
    Posts
    36
    Helped
    0 / 0
    Points
    1,223
    Level
    7

    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.



--[[ ]]--