title: How to count pressed keys on FPGA spartan board
body: <p>I`m using FPGA Spartan 2 board and want to count the keys pressed from Keyboard
  this is my VHDL code :</p>
  
  <pre><code>library ieee ;
  use ieee.std_logic_1164.all;
  use ieee.std_logic_arith.all;
  use ieee.std_logic_unsigned.all;
  use ieee.numeric_std.all;
  
  ENTITY Keyboard IS
   PORT(CLOCK : IN STD_LOGIC;
        RESET : IN STD_LOGIC;
        RK : IN STD_LOGIC_VECTOR(3 DOWNTO 1);
        DE : OUT STD_LOGIC_VECTOR(3 DOWNTO 1);
        Invalid_Key : OUT STD_LOGIC := '0';
        Seg1 : OUT STD_LOGIC_VECTOR(7 Downto 0);
        Seg2 : OUT STD_LOGIC_VECTOR(7 Downto 0);
        LEDRow1 : OUT STD_LOGIC_VECTOR(7 Downto 0);
        LEDRow2 : OUT STD_LOGIC_VECTOR(7 Downto 0);       
        Key : OUT STD_LOGIC_VECTOR(0 TO 15));
  END Keyboard;
  
  Architecture Behavier OF Keyboard IS
   Signal CLK : STD_LOGIC_VECTOR(23 DOWNTO 0);
   Signal KC : STD_LOGIC_VECTOR(1 DOWNTO 0);
   Signal KEY_PUSH : STD_LOGIC_VECTOR(4 DOWNTO 0);
   Signal KeyTemp : STD_LOGIC_VECTOR(1 TO 16) := "0000000000000000";
   Signal Counter : STD_LOGIC_VECTOR(4 downto 0) := "00000";
  Begin
   DE(3) &lt;= '0';
   DE(2 DOWNTO 1) &lt;= KC;
   KEY_PUSH &lt;= KC &amp; RK;
  
   Process(KEY_PUSH)
   begin
    Case KEY_PUSH is
     WHEN "11101" =&gt; --0
      if Counter &lt;= 15 then
        Invalid_Key &lt;= '0';
        Counter &lt;= Counter + 1;
       KeyTemp(conv_integer(Counter)) &lt;= '0';           
      else
       Invalid_Key &lt;= '1';
      end if;
     WHEN "00110" =&gt; --1
      if Counter &lt;= 15 then
        Invalid_Key &lt;= '0';
       Counter &lt;= Counter + 1;
        KeyTemp(conv_integer(Counter)) &lt;= '1';
      else
       Invalid_Key &lt;= '1';
      end if;
  
     WHEN "00101" =&gt;
      Invalid_Key &lt;= '1';  -- 2
     WHEN "00011" =&gt;
      Invalid_Key &lt;= '1';  -- 3
     WHEN "01110" =&gt;
      Invalid_Key &lt;= '1';  -- 4
     WHEN "01101" =&gt;
      Invalid_Key &lt;= '1';  -- 5
     WHEN "01011" =&gt;
      Invalid_Key &lt;= '1';  -- 6
     WHEN "10110" =&gt;
      Invalid_Key &lt;= '1';  -- 7
     WHEN "10101" =&gt;
      Invalid_Key &lt;= '1';  -- 8
     WHEN "10011" =&gt;
      Invalid_Key &lt;= '1';  -- 9
     WHEN "11011" =&gt; -- #
      Invalid_Key &lt;= '1';  -- #   
  
     WHEN "11110" =&gt; -- *
       Invalid_Key &lt;= '0';
      KeyTemp &lt;= "0000000000000000";
      Counter &lt;= "00000";
     WHEN OTHERS =&gt;   
      Invalid_Key &lt;= '0';
    End Case;
  
     case Counter is
      when "00000" =&gt; -- 0
       Seg1 &lt;= "00111111";
        Seg2 &lt;= "00111111";
      when "00001" =&gt; -- 1
       Seg1 &lt;= "00111111";
        Seg2 &lt;= "00000110";
      when "00010" =&gt; -- 2
       Seg1 &lt;= "00111111";
        Seg2 &lt;= "01011011";
      when "00011" =&gt; -- 3
       Seg1 &lt;= "00111111";
        Seg2 &lt;= "01001111";
      when "00100" =&gt; -- 4
       Seg1 &lt;= "00111111";
        Seg2 &lt;= "01100110";
      when "00101" =&gt; -- 5
       Seg1 &lt;= "00111111";
        Seg2 &lt;= "01101101";
      when "00110" =&gt; -- 6
       Seg1 &lt;= "00111111";
        Seg2 &lt;= "01111101";
      when "00111" =&gt; -- 7
       Seg1 &lt;= "00111111";
        Seg2 &lt;= "00100111";
      when "01000" =&gt; -- 8
       Seg1 &lt;= "00111111";
        Seg2 &lt;= "01111111";
      when "01001" =&gt; -- 9
       Seg1 &lt;= "00111111";
        Seg2 &lt;= "01101111";
      when "01010" =&gt; -- 10
       Seg1 &lt;= "00000110";
        Seg2 &lt;= "00111111";
      when "01011" =&gt; -- 11
       Seg1 &lt;= "00000110";
        Seg2 &lt;= "00000110";
      when "01100" =&gt; -- 12
       Seg1 &lt;= "00000110";
        Seg2 &lt;= "01011011";
      when "01101" =&gt; -- 13
       Seg1 &lt;= "00000110";
        Seg2 &lt;= "01001111";
      when "01110" =&gt; -- 14
       Seg1 &lt;= "00000110";
        Seg2 &lt;= "01100110";
      when "01111" =&gt; -- 15
       Seg1 &lt;= "00000110";
        Seg2 &lt;= "01101101";
      when "10000" =&gt; -- 16
       Seg1 &lt;= "00000110";
        Seg2 &lt;= "01111101";
      when others =&gt;
       Seg1 &lt;= "00000000";
       Seg2 &lt;= "00000000";      
     end case;
  
    LEDRow1 &lt;= KeyTemp(1 to 8);
    LEDRow2 &lt;= KeyTemp(9 to 16);  
  
    if Counter = 16 then
     Key &lt;= KeyTemp;
    end if;
   End Process;
  
   Process(CLOCK, CLK)
   begin
    IF (Clock'EVENT AND Clock='1') THEN
     Clk &lt;= Clk + 1;
    END IF;    
   end Process;   
  
   Process(Reset, CLK(10))
   begin
    IF RESET = '1' THEN
     KC &lt;= "00";
    ELSIF (CLK(10) 'EVENT AND CLK(10)='1') THEN 
     KC &lt;= KC + 1;    
    END IF;
   end Process;   
  END Behavier;
  </code></pre>
  
  <p>only 1 and 0 keys are acceptable</p>
  
  <p>I want to show counter value in 2 7segment and show the 0 and 1s in two line of LED Matrix, but there a problem on counter, I think the problem is "Key_PUSH" or "RK" are changing many times when I press a key.</p>
  
  <p>How I can create a counter for pressed keys ?</p>