4x4 Keypad Encoder VHDL

Status
Not open for further replies.

Kreeker

Newbie level 1
Joined
Apr 28, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,292
Hey Guys,

I'm designing a combinational lock using a 4x4 keypad input. I'm sure you guys are familiar with this type of keypad; 4 bits for input to the keypad, and 4 bits for output of the keypad.


Here is my code so far for my Keypad module:
Code:
	begin
		input : process (clk)
		begin
			if reset = '1' then
				row_out <= "0001";
				current_Input <= "00000";
				previous_Input <= "00000";
			elsif clk'event and clk = '1' then
				previous_Input <= current_Input;
				if columns = "1000" then
						if row_out = "1000" then
							current_Input <= "00001";
						elsif row_out = "0100" then
							current_Input <= "00010";
						elsif row_out = "0010" then
							current_Input <= "00011";
						elsif row_out = "0001" then
							current_Input <= "00100";
						end if;
				elsif columns = "0100" then
						if row_out = "1000" then
							current_Input <= "00101";
						elsif row_out = "0100" then
							current_Input <= "00110";
						elsif row_out = "0010" then
							current_Input <= "00111";
						elsif row_out = "0001" then
							current_Input <= "01000";
						end if;		
				elsif columns = "0010" then
						if row_out = "1000" then
							current_Input <= "01001";
						elsif row_out = "0100" then
							current_Input <= "01010";
						elsif row_out = "0010" then
							current_Input <= "01011";
						elsif row_out = "0001" then
							current_Input <= "01100";
						end if;	
				elsif columns = "0001" then
					if row_out = "1000" then
						current_Input <= "01101";
					elsif row_out = "0100" then
						current_Input <= "01110";
					elsif row_out = "0010" then
						current_Input <= "01111";
					elsif row_out = "0001" then
						current_Input <= "10000";
					end if;
				else
					current_Input <= "00000";
				end if;
				
				if row_out = "1000" then
					row_out <= "0100";
				elsif row_out = "0100" then
					row_out <= "0010";
				elsif row_out = "0010" then
					row_out <= "0001";
				else 
					row_out <= "1000";
				end if;
				
				if previous_Input = current_Input then
					LedTest <= "00000";
				else
					LedTest <= current_Input;
				end if;
				
				previous_Input <= current_Input;				
		end if;
		end process;
		

		rows <= row_out;
end Behavioral;

I think I have the right idea, but what is missing is some type of debouncing... and I'm having trouble figuring this out.

Thanks for your help in advance
 

hi
u can use this method that check every press key 2 time .it means that u can write for example :
if row_out = "1000" then
if row_out = "1000" then
current_Input <= "00001";
elsif row_out = "0100" then
elsif row_out = "0100" then
current_Input <= "00010";

i hope this is useful.i check it in my project and its work.its work like a filter or denouncing method.
be success
 

i hope this is useful.i check it in my project and its work.its work like a filter or denouncing method.
Are you sure about your statement?

IMHO, this test happens in the same clock period, so this is not working as a debouncer
 

we have to type of computing in VHDL
sequential and concurrent.
Conditional rule like if , are sequential.means that this program check every if every one after the other
 

we have to type of computing in VHDL
sequential and concurrent.
Conditional rule like if , are sequential.means that this program check every if every one after the other

I know what concurrent and sequential is, but your code won't be able to debounce a switch.

Assuming your code would look like (this code doesn't operate properly)
Code:
process (clk, rst)
begin
   if rst = '0' then
      ...
   elsif rising_edge (clk) then
      if row_out = "1000" then
         if row_out = "1000" then
            current_Input <= "00001";
         elsif row_out = "0100" then
         elsif row_out = "0100" then
            current_Input <= "00010";
         end if;
      end if;
   end if;
end process;

be assured that the two 'if row_out = "1000" in this process won't take place at different clock pulses)
 

u can use this method in this way : declare a variable like x.in one clock read the data and after that increase the variable.in the second clock check the variable and data again.

process (clk, rst)
begin
if rst = '0' then
...
elsif rising_edge (clk) then
if row_out = "1000" then
x<=x+1;
end if;
end process;

process (clk, x)
begin
if x = "2" then
if row_out = "1000" then
current_Input <= "00001";
x<=0;
end if;
end if;
end process;
 

u can use this method in this way : declare a variable like x.in one clock read the data and after that increase the variable.in the second clock check the variable and data again.

You are making it very difficult.
The code will have a problem too (up to you to find it)

something that will work:
Code:
process (clock)
begin
  if rising_edge(clock);
      SHIFT_PB(2 Downto 0) <= SHIFT_PB(3 Downto 1);
      SHIFT_PB(3) <= PB;
      If SHIFT_PB(3 Downto 0)="1111" THEN
        PB_DEBOUNCED <= '1';
      ELSE 
        PB_DEBOUNCED <= '0';
      End if;
end process;

Just change the code to work with your keypad.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…