VHDL keypad code issues

时光毁灭记忆、已成空白 提交于 2020-01-17 04:32:08

问题


I have a 4x3 keypad, i wrote this FSM for interfacing it with my Nexys2 board, trouble I am having here is

  1. When I run the code, the LEDs glow without any key pressed, it shows random combinations automatically

  2. When I press a key it shows that particular combination then goes on to the next condition of ROW without any key pressed. And sometimes it does not even respond if i press a key.

What is happening? What is wrong with this code? I am clueless. Can someone point out the mistakes and suggest some solution? Here is my code

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;


entity keypad_3x4 is
     Port ( CLK     : in  STD_LOGIC;
              RESET     : in  STD_LOGIC;
              ROW   : in  STD_LOGIC_VECTOR (3 downto 0);
              COL   : out STD_LOGIC_VECTOR (2 downto 0);
              LED       : out STD_LOGIC_VECTOR (3 downto 0)
              );
end keypad_3x4;


architecture Behavioral of keypad_3x4 is
architecture Behavioral of keypad_3x4 is


 TYPE STATE_TYPE is
    (   RESET_ST,
        S1,
        S2,
        S3,
        S4,
        S5,
        S6
    );

signal  state:  STATE_TYPE;
begin

 process (CLK, RESET)
 begin

    if  (RESET = '1') then
        state       <= RESET_ST;    
    elsif   (CLK'event and CLK = '1') then

    case (state) is 

    WHEN RESET_ST       =>
            LED             <= (others => '0');
            COL         <= (others => '0');
            state           <= S1;

    WHEN S1         =>
        COL             <= "001";       --C1 selected
        LED             <= (others => '0');
        state           <= S2;

    WHEN S2         =>
        if  ROW         <= "0001" then
                led         <= "0001";  --1     
        elsif ROW       <= "0010" then
                led         <= "0100";  --4     
        elsif ROW       <= "0100" then
                led         <= "0111";  --7     
        elsif ROW       <= "1000" then
                led         <= "1111";  --*     
        else
                LED         <= (others => '0');
                state       <= S3;
        end if;

    WHEN S3         =>
        COL             <= "010";       --C2 selected
        LED         <= (others => '0');
        state           <= S4;

    WHEN S4     =>
        if  ROW <= "0001" then
                led <= "0010";  --2 
        elsif ROW <= "0010" then
                led <= "0101";  --5     
        elsif ROW <= "0100" then
                led <= "1000";  --8
        elsif ROW <= "1000" then
                led <= "0000";  --0
        else
                LED         <= (others => '0');
                state       <= S5;
        end if;

    WHEN S5     =>
        COL             <= "100";       --C3 selected
        LED             <= (others => '0');
        state           <= S6;

    WHEN S6     =>
        if  ROW <= "0001" then
                led <= "0011";  --3
        elsif ROW <= "0010" then
                led <= "0110";  --6
        elsif ROW <= "0100" then
                led <= "1001"; --9
        elsif ROW <= "1000" then
                led <= "1111";  --#
        else
                LED         <= (others => '0');
                state       <= RESET_ST;
        end if;

    WHEN others =>
                state       <= RESET_ST;    
    END case;
END if;
END process;

end Behavioral;

来源:https://stackoverflow.com/questions/24822545/vhdl-keypad-code-issues

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!