Results 1 to 7 of 7

Thread: How to use a for loop for repetitive timed actions

  1. #1
    Join Date
    Jul 2015
    Posts
    4
    Rep Power
    1

    Default How to use a for loop for repetitive timed actions

    I am trying to figure out how to use a for loop for some repetitive timed actions. A snippet of the code I am using right now is shown below, although only showing 2 repeats. I haven't been able to come up with something that seems like it would work.

    Marie Stoffer

    CASE ten_sec_cnt IS
    WHEN "000" =>
    IF ((rollovr_cnt = X"0") and (duration = X"00")) THEN
    next_red <= '0'; -- turn red LED on
    next_av_done <= avdone;
    next_state <= state;
    ELSIF ((rollovr_cnt = X"1") and (duration = X"F2")) THEN -- time = 5 sec
    next_red <= '1'; -- turn red LED off
    next_av_done <= avdone;
    next_state <= state;
    ELSIF ((rollovr_cnt = X"2") and (duration = X"B9")) THEN -- time = 7 sec, double-flash, start of 10 seconds
    next_red <= '0'; -- turn red LED on
    next_av_done <= avdone;
    next_state <= state;
    ELSIF ((rollovr_cnt = X"2") and (duration = X"D2")) THEN -- time = 7250 ms
    next_red <= '1'; -- turn red LED off
    next_av_done <= avdone;
    next_state <= state;
    ELSIF ((rollovr_cnt = X"3") and (duration = X"04")) THEN -- time = 7750 ms
    next_red <= '0'; -- turn red LED on
    next_av_done <= avdone;
    next_state <= state;
    ELSIF ((rollovr_cnt = X"3") and (duration = X"1C")) THEN -- time = 8 sec
    next_red <= '1'; -- turn red LED off
    next_av_done <= avdone;
    next_state <= state;
    ELSIF ((rollovr_cnt = X"3") and (duration = X"80")) THEN -- time = 9 sec
    next_red <= '0'; -- turn red LED on
    next_av_done <= avdone;
    next_state <= state;
    ELSIF ((rollovr_cnt = X"3") and (duration = X"99")) THEN -- time = 9250 ms
    next_red <= '1'; -- turn red LED off
    next_av_done <= avdone;
    next_state <= state;
    ELSIF ((rollovr_cnt = X"3") and (duration = X"CA")) THEN -- time = 9750 ms
    next_red <= '0'; -- turn red LED on
    next_av_done <= avdone;
    next_state <= state;
    ELSE
    next_red <= red;
    next_av_done <= avdone;
    next_state <= state;
    END IF;
    WHEN "001" =>
    IF ((rollovr_cnt = X"0") and (duration = X"00")) THEN -- time = 10 sec
    next_red <= '1'; -- turn red LED off
    next_av_done <= avdone;
    next_state <= state;
    END IF;
    WHEN OTHERS => null;
    END CASE;

  2. #2
    Tricky is offline Moderator **Forum Master**
    Join Date
    Oct 2008
    Posts
    5,267
    Rep Power
    1

    Default Re: How to use a for loop for repetitive timed actions

    For loops unroll into parallel or sequential logic depending on their usage. I suggest going back to your circuit diagram and ensuring that it meets your design specification. Modify your diagram before writing any code

  3. #3
    Join Date
    Jul 2015
    Posts
    4
    Rep Power
    1

    Default Re: How to use a for loop for repetitive timed actions

    Quote Originally Posted by Tricky View Post
    For loops unroll into parallel or sequential logic depending on their usage. I suggest going back to your circuit diagram and ensuring that it meets your design specification. Modify your diagram before writing any code


    This is definitely sequential logic. It has to be since the LED gets turned on for 250ms and then off for 500ms then on again for 250ms and then off for 1 second and then this same sequence repeats 4 more times, then repeats every 10 seconds for 15 minutes. Where I am having the problem is figuring out how to write this as a for loop and how to use a timer in the for loop. I have pages of code to do much of this sequence without using a for loop but it seems extremely inefficient.

  4. #4
    Tricky is offline Moderator **Forum Master**
    Join Date
    Oct 2008
    Posts
    5,267
    Rep Power
    1

    Default Re: How to use a for loop for repetitive timed actions

    What you describe sounds like a software programming concept. This is not programming, this is HDL (hardware description). In HDL, for loops are just a way to repeatedly describe blocks of similar logic. They do not cover passages of time.

  5. #5
    Join Date
    Jul 2015
    Posts
    4
    Rep Power
    1

    Default Re: How to use a for loop for repetitive timed actions

    The logic turns an LED on and off and increments a counter (or several). The time is measured by the value of the counter which is clocked at a specific frequency.

  6. #6
    Tricky is offline Moderator **Forum Master**
    Join Date
    Oct 2008
    Posts
    5,267
    Rep Power
    1

    Default Re: How to use a for loop for repetitive timed actions

    Quote Originally Posted by mafstoffer View Post
    The logic turns an LED on and off and increments a counter (or several). The time is measured by the value of the counter which is clocked at a specific frequency.
    Yes. And at no point is a for loop useful for you. A for loop has no memory between clock cycles.
    Think about the logic circuit, not the software code.

  7. #7
    Join Date
    Jun 2013
    Location
    The Netherlands
    Posts
    417
    Rep Power
    1

    Default Re: How to use a for loop for repetitive timed actions

    What might help is drawing the circuit. When you have a clear picture of how the multiplexers, comparators, registers etc. are connected you can write code to represent the same circuit. (You can use the RTL viewer to check the cuircuit resulting from the code.)

Similar Threads

  1. DE1 SoC I2C-1 shows i2c_designware ffc05000.i2c: controller timed out
    By madhurkiran.h@gmail.com in forum SoC Linux
    Replies: 0
    Last Post: July 20th, 2016, 10:56 AM
  2. processes: while loop does not work, for loop does work. Why?
    By Gronk in forum General Altera Discussion
    Replies: 12
    Last Post: July 10th, 2013, 01:39 AM
  3. DHCP timed out, going back to default IP address(es)
    By saranshmeh in forum General Altera Discussion
    Replies: 5
    Last Post: November 22nd, 2012, 03:08 AM
  4. Replies: 1
    Last Post: November 20th, 2012, 11:08 PM
  5. DHCP Timed Out problem in simple socket server
    By caridee in forum General Software Forum
    Replies: 11
    Last Post: May 15th, 2012, 12:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •