You have no items in your shopping cart.

Subtotal: 0.00

Matrix Keypad interface with Spartan6 FPGA Development Kit

Matrix Keypad interfacing with Spartan6 FPGA Development Kit

Matrix Keypad

Keypad is most commonly used input device in electronics. To Simply number of input keypad lines to controller device leads to formation of matrix keypad. Matrix keyboard consist of NxN number of push button arranged in rows and column. 2N is the number of lines required to get the input of NxN Push Button 

Matrix keypad consists of a set of buttons similar to an alphanumeric keyboard provided with keys usually marked with letters or numbers and various extra keys. Embedded systems which require user interaction must be interfaced with devices that accept user input such as a keypad.

Interfacing Keypad with Spartan6 FPGA Development Kit

The Spartan-3 FPGA board has 4x4 Matrix Keypad, indicated as in Figure. Keypads arranged by matrix format, each row and column section pulled by high, all row lines and column lines connected directly by the I/O pins.

                   Interfacing Keypad with Spartan3e FPGA Development Kit

Matrix Keypad Placement in Spartan6 FPGA Development Kit

         Matrix Keypad Placement in Spartan3e FPGA Development Kit

VHDL Code Description for Matrix Keypad to LED Interface 

The Spartan6 FPGA Development Kit Scan continuously for key press. Once the NxN key pressed the following key press will be represented in 4- bit binary value and displayed in the LED’s. 

VHDL Code for Matrix Keypad to LED Interface

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

 

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

USE IEEE.STD_LOGIC_ARITH.ALL;

USE IEEE.STD_LOGIC_UNSIGNED.ALL;

 

entity matrix_keypad is

port(

clock,rst : in std_logic;

col_line : in   std_logic_vector(3 downto 0);

row_line : out std_logic_vector(3 downto 0);

led : out   std_logic_vector(15 downto 0)

);

end matrix_keypad;

 

architecture Behavioral of matrix_keypad is

signal temp : std_logic_vector(29 downto 0);

begin

test: process(clock,rst) is

begin

if(rst='0') then

led <= "1111111111111111";

elsif rising_edge(clock) then

temp <= temp + 1;

      case temp(10 downto 8) is

      when "000" =>

       row_line <= "0111"; --first row

      when "001" =>  

       if col_line = "0111" then

              led <= "0011001100110011"; -- 3

       elsif col_line = "1011" then

              led <= "0010001000100010"; -- 2

       elsif col_line = "1101" then

              led <= "0001000100010001"; -- 1

       elsif col_line = "1110" then

              led <= "0000000000000000"; -- 0

       end if;

      when "010" =>

       row_line <= "1011"; --second row

      when "011" =>

       if col_line = "1110" then

              led <= "0100010001000100"; -- 4

       elsif col_line = "1101" then

              led <= "0101010101010101"; -- 5

       elsif col_line = "1011" then

              led <= "0110011001100110"; -- 6

       elsif col_line = "0111" then

              led <= "0111011101110111"; -- 7

       end if;

      when "100" =>

       row_line <= "1101"; --third row

      when "101" =>

       if col_line = "1110" then

              led <= "1000100010001000"; -- 8

       elsif col_line = "1101" then

              led <= "1001100110011001"; -- 9

       elsif col_line = "1011" then

              led <= "1010101010101010"; -- a

       elsif col_line = "0111" then

              led <= "1011101110111011"; -- b

       end if;

      when "110" =>

       row_line <= "1110"; --fourth row

      when "111" =>

       if col_line = "1110" then

              led <= "1100110011001100"; -- C

       elsif col_line = "1101" then

              led <= "1101110111011101"; -- d

       elsif col_line = "1011" then

              led <= "1110111011101110"; -- e

       elsif col_line = "0111" then

              led <= "1111111111111111"; -- f

       end if;

      when others => led <= "0000000000000000";

      end case;

end if;

end process;

end Behavioral;

User Constraint File

NET "row_line(0)"  LOC = "p109";

NET "row_line(0)"  LOC = "B11";
NET "row_line(1)"  LOC = "A12";
NET "row_line(2)"  LOC = "C11";
NET "row_line(3)"  LOC = "B12";
NET "clock"  LOC = "C9"  ;
NET "col_line(0)"  LOC = "D11"  ;
NET "col_line(1)"  LOC = "A14"  ;
NET "col_line(2)"  LOC = "F13"  ;
NET "col_line(3)"  LOC = "C14"  ;
NET "led[0]" LOC = M16;
NET "led[1]" LOC = P18;
NET "led[2]" LOC = N18;
NET "led[3]" LOC = N17;
NET "led[4]" LOC = L15;
NET "led[5]" LOC = U18;
NET "led[6]" LOC = M18;
NET "led[7]" LOC = U17;
NET "led[8]" LOC = K18;
NET "led[9]" LOC = K14;
NET "led[10]" LOC = H14;
NET "led[11]" LOC = J13;
NET "led[12]" LOC = K17;
NET "led[13]" LOC = H13;
NET "led[14]" LOC = L12;
NET "led[15]" LOC = J18;
NET "rst"  LOC = G13  ;