title: Counter with push button switch design using VHDL and Xilinx
body: <p>I'm very new to VHDL and XILINX ISE. I use the version 13.2 for Xilinx ISE.</p>
  
  <p>I want to design a very simple counter with the following inputs:</p>
  
  <ul>
  <li>Direction</li>
  <li>Count</li>
  </ul>
  
  <p>The count input will be assigned to a button and I want the counter to count up or down according to direction input when the button is pressed. I have written a sample VHDL before this one. It had a clock input and It was counting according to the clock input. Now I want it to count when I press the button instead of counting synchronously.</p>
  
  <p>Here's my VHDL code (please tell me if my code have a logical or any other flaw):</p>
  
  <pre><code>entity counter is
      Port ( COUNT_EN : in  STD_LOGIC;
             DIRECTION : in  STD_LOGIC;
             COUNT_OUT : out  STD_LOGIC_VECTOR (3 downto 0));
  end counter;
  
  architecture Behavioral of counter is
  
  signal count_int : std_logic_vector(3 downto 0) := "0000";
  begin
  process 
  begin
      if COUNT_EN='1' then
          if DIRECTION='1' then   
              count_int &lt;= count_int + 1;
          else
              count_int &lt;= count_int - 1;
          end if;
      end if;
  end process;
  COUNT_OUT &lt;= count_int;
  end Behavioral;
  </code></pre>
  
  <p>I use Spartan xc3s500e and I placed the inputs accordingly. Below is my .ucf file:</p>
  
  <pre><code>#Created by Constraints Editor (xc3s500e-fg320-5) - 2013/03/18
  NET "COUNT_EN" LOC = K17;
  NET "COUNT_OUT[0]" LOC = F12;
  NET "COUNT_OUT[1]" LOC = E12;
  NET "COUNT_OUT[2]" LOC = E11;
  NET "COUNT_OUT[3]" LOC = F11;
  NET "DIRECTION" LOC = L13;
  #Created by Constraints Editor (xc3s500e-fg320-5) - 2013/03/18
  NET "COUNT_EN" CLOCK_DEDICATED_ROUTE = FALSE;
  </code></pre>
  
  <p>I needed to change the last line because I was getting the error:</p>
  
  <pre><code>This will not allow the use of the fast path between the IO and the Clock...
  </code></pre>
  
  <p>After having this error gone, I programmed the device. But the output (leds) acted crazy. They sometimes stood still for a few seconds, sometimes just flashed very fast. I could not figure out where my mistake is. I would appreciate any help, some beginner tutorials are greatly appreciated (the links i found directed me to xilinx's documentations and they seemed quite complicated for a beginner).</p>