You have no items in your shopping cart.

Subtotal: 0.00

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 Spartan3 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 Spartan3 FPGA Development Kit

Matrix Keypad Placement in  Spartan3 FPGA Development Kit


Matrix Keypad Placement in Spartan3 FPGA Development Kit

VHDL Code Description for Matrix Keypad to LED Interface

The Spartan3 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 = "p117";
NET "row_line(1)"  LOC = "p116";
NET "row_line(2)"  LOC = "p115";
NET "row_line(3)"  LOC = "p114";
NET "clock"  LOC = "p181"  ;
NET "col_line(0)"  LOC = "p113"  ;
NET "col_line(1)"  LOC = "p111"  ;
NET "col_line(2)"  LOC = "p109"  ;
NET "col_line(3)"  LOC = "p108"  ;
NET "led[0]" LOC = P36;
NET "led[1]" LOC = P37;
NET "led[2]" LOC = P39;
NET "led[3]" LOC = P40;
NET "led[4]" LOC = P42;
NET "led[5]" LOC = P43;
NET "led[6]" LOC = P44;
NET "led[7]" LOC = P45;
NET "led[8]" LOC = P62;
NET "led[9]" LOC = P63;
NET "led[10]" LOC = P64;
NET "led[11]" LOC = P65;
NET "led[12]" LOC = P67;
NET "led[13]" LOC = P68;
NET "led[14]" LOC = P71;
NET "led[15]" LOC = P72;
NET "rst"  LOC = p46  ;