Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

DE1 Board Read KEY

I need to press and hold key 1 and than press key 2 to increase value. How to Read keys only if both keys are pressed. This is what is have which is not working correct. (programming languages vhdl).

if key(0) and key(1) are pessed do somthing

PORT (

KEY : IN STD_LOGIC_VECTOR(3 DOWNTO 0);

);

SIGNAL A, B, C, D : STD_LOGIC_VECTOR(1 DOWNTO 0);

BEGIN

A <= Not(KEY(0) & KEY(1));

B <= Not(KEY(0) & KEY(2));

C <= Not(KEY(0) & KEY(3));

Readkey: process(KEY)

begin

if (A = 1) then

D <= "00"; -- 1

end if;

if (B = 1) then

D <= "01"; -- 2

end if;

if (C = 1) then

D <= "10"; -- 3

end if;

end process;

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    A is a vector. It will have the value "00" when no key is pressed, and the value "11" when both are. So you can simply have:

    if (A = "11") then

    Your process' sensitivity list should have all your inputs, in that case A,B and C. I'm almost sure that if you simulate this, the process would be triggered on a KEY change but would still see the previous values of A, B and C because of the delta delay. It wouldn't change anything for Quartus synthesis though.

    Ps: your component has no output