+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Newbie level 1
    Points: 299, Level: 3

    Join Date
    Apr 2011
    Posts
    1
    Helped
    0 / 0
    Points
    299
    Level
    3

    4x4 Keypad Encoder VHDL

    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 :)

    •   AltAdvertisment

        
       

  2. #2
    Junior Member level 2
    Points: 969, Level: 7

    Join Date
    Apr 2009
    Posts
    22
    Helped
    4 / 4
    Points
    969
    Level
    7

    Re: 4x4 Keypad Encoder VHDL

    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



    •   AltAdvertisment

        
       

  3. #3
    Advanced Member level 2
    Points: 4,734, Level: 16

    Join Date
    Oct 2003
    Location
    Belgium
    Posts
    514
    Helped
    73 / 73
    Points
    4,734
    Level
    16

    Re: 4x4 Keypad Encoder VHDL

    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



    •   AltAdvertisment

        
       

  4. #4
    Junior Member level 2
    Points: 969, Level: 7

    Join Date
    Apr 2009
    Posts
    22
    Helped
    4 / 4
    Points
    969
    Level
    7

    Re: 4x4 Keypad Encoder VHDL

    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



  5. #5
    Advanced Member level 2
    Points: 4,734, Level: 16

    Join Date
    Oct 2003
    Location
    Belgium
    Posts
    514
    Helped
    73 / 73
    Points
    4,734
    Level
    16

    Re: 4x4 Keypad Encoder VHDL

    Quote Originally Posted by KarajRobo View Post
    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)



    •   AltAdvertisment

        
       

  6. #6
    Junior Member level 2
    Points: 969, Level: 7

    Join Date
    Apr 2009
    Posts
    22
    Helped
    4 / 4
    Points
    969
    Level
    7

    Re: 4x4 Keypad Encoder VHDL

    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;



  7. #7
    Advanced Member level 2
    Points: 4,734, Level: 16

    Join Date
    Oct 2003
    Location
    Belgium
    Posts
    514
    Helped
    73 / 73
    Points
    4,734
    Level
    16

    Re: 4x4 Keypad Encoder VHDL

    Quote Originally Posted by KarajRobo View Post
    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.



--[[ ]]--