0

I'm writing an pong game vhdl code for spartan 3E starter kit. I want to control the game pad with my PS2 keyboard. For this i need to generate up and down signals from the keyboard received scan code.

Here's sample code

   -- Instantiate key_board controller
    my_keyobard : entity work.ps2_key(Behavioral)
                    port map( ps2_clk => ps2_clk, ps2_data => ps2_data, clk => clk,
                    data_out => data);

   process(data)
   begin
          case data is
                 when X"15" => up <= '1'; -- Q key for UP
                 when X"1C' => down <= '1'; -- A key for DOWN
                 when others => up <= '0'; down <= '0';
          end case;
   end process;

But if I use this code the up key will remain '1' HIGH always, even after relesing the Q key on the keyboard. I want up signal to remain to high only till i hold the Q button down if I release it then up signal must return to '0'. Basically i want my keyboard keys to function like normal button. If i press and hold then it must give HIGH signal else if released it must give LOW signal.

Sumanth
  • 115
  • 1
  • 1
  • 5

3 Answers3

0

others clauses are ignored by synthesis (usually, unless you tell them not to)

process(data)
   begin
          up <= '0'; down <= '0';
          case data is
                 when X"15" => up <= '1'; -- Q key for UP
                 when X"1C" => down <= '1'; -- A key for DOWN
          end case;
   end process;

Have you simulated - it should work fine in simulation the way you had it.

Martin Thompson
  • 16,395
  • 1
  • 38
  • 56
0

I believe PS2 keyboard Protocol sends a command word, then the keyboard code when the button is pressed, then two command words and a keyboard code when released. Are you dealing with this elsewhere? We need to know more about your "Data out" from your keyboard controller. Does it latch the data signal from the keyboard? If you have data reset when the key is released then your code should work as desired.

Page 8 is what I am talking about http://www.cse.nd.edu/courses/cse20221/www/handouts/L21_%20PS2%20Keyboard.pdf

Paul Seeb
  • 6,006
  • 3
  • 26
  • 38
0

The PS/2 keyboard protocol is more complicated than that. You'll need to implement a stateful decoder.

In brief:

  1. When nothing happens, both ps2_data and ps2_clk are always '1'.
  2. On an event, a keyboard sends a start bit (0), data bits one-by-one, then a stop bit (1). The bits are clocked with ps2_clk.
  3. When a key is pressed and held, the scan code is sent repeatedly with a certain interval.
  4. When a key is depressed, 'F0' code, then the scan code, is sent (it's a bit more complex for so-called "extended" keys that include the arrow keys).

See Xilinx Spartan-3E FPGA Starter Kit Board User Guide, "PS/2 Mouse/Keyboard Port" section, and/or generic PS/2 electric protocol description (the latter essentially repeats the former in more detail).

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152