title: VHDL counter/timer
body: <p>I'm a VHDL newbie and I'm struggling with the following idea. I think I still misunderstand the idea of counters and timers in VHDL. I will explain it with a simple blinking LED diode. (BTW I'm learning on Spartan-3E FPGA kit.) <br> So here is my code (I'm not using reset yet)</p>
  
  <pre><code>entity top_level is
    Port( clk : in STD_LOGIC;
          led1 : out STD_LOGIC);
  end top_level;
  
  architecture Behavioral of top_level is
      signal timer : STD_LOGIC_VECTOR(25 downto 0) := "00000000000000000000000000"; 
      signal reset: boolean:= false;
  
  begin 
  
      process (clk) 
      begin
          led1 &lt;= '1';
          if clk='1' and clk'event then
              if reset &lt;= true then
                  timer &lt;= (others =&gt; '0');
              end if;
              timer &lt;= timer + 1;
          end if;
  
          if timer &lt;= "11100100111000011100000000" then
              led1 &lt;= '0';
          end if;
      end process;
  end Behavioral;
  </code></pre>
  
  <p>The oscillator frequency is 50 MHz so one period is 20 ns. If I want to blink with a LED for 1.2 second (which makes 60 000 000 cycles) I need to create a 26 bit vector. So I created a process which is triggered by clk change.<br> 
  <b>WHAT I THINK IT SHOULD DO:</b>
  the first line of code is a logic 1 assignment to led1. So the led1 should light until the counter won't count 60 000 000 cycles. When counter counts 60 000 000 cycles, the led logic state should switch to 0 which means no light. As the maximum value of 26 bit number is 67 108 863, the LED should light for 60 000 000 cycles and be turned off for the remaining 7 108 863 cycles. Isn't that right ?<br>
  <b>WHAT IT DOES:</b>My impression is, that it's kinda reversed. The LED is off for the most of the time (67 108 063 cycles) and lights for 7 108 863 cycles. Why is this happening ? I don't really get it.<br><br>
  <b>Additional question:</b> How can I achieve to run this process only once/twice/...? E.g. I want to blink with my LED 3 times and then turn it off. Because as far as I know after reaching maximum 26 bit number, the time vector will start counting from the beginning (from 0). And so on, endlessly.</p>