Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

How to simulate pressed key ?

Status
Not open for further replies.

zorro3k

Newbie level 4
Joined
May 4, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,331
I have a decoder for a keypad

HTML:
ENTITY key IS
PORT (
  clk          : IN  STD_LOGIC;                       -- Clock source and
  resetn       : IN  STD_LOGIC;                       -- Reset on global inputs
  row          : IN  STD_LOGIC_VECTOR (3 DOWNTO 0); 
  col          : OUT STD_LOGIC_VECTOR (3 DOWNTO 0);   -- Drive columns
  
END hexkbd;

ARCHITECTURE keys OF hexkbd IS
  SIGNAL key_pressed  : STD_LOGIC;          -- High when a key pressed
  SIGNAL d       : STD_LOGIC_VECTOR (3 DOWNTO 0); 

BEGIN
  -- Scan the keyboard until a key is pressed
  PROCESS (clk, key_pressed)
  BEGIN
  IF (resetn = '0') THEN d <= "0000";              -- asynchronous reset
  ELSIF (clk'EVENT AND clk = '1') THEN
    IF (key_pressed = '0') THEN d <= d + 1; END IF;
  END IF;                -- Counter stops counting when a key is pressed
  END PROCESS;

  -- Column drivers, active low
  col(0)  <= '0' WHEN d(3 DOWNTO 2) = "00" ELSE '1';
  col(1)  <= '0' WHEN d(3 DOWNTO 2) = "01" ELSE '1';
  col(2)  <= '0' WHEN d(3 DOWNTO 2) = "10" ELSE '1';
  col(3)  <= '0' WHEN d(3 DOWNTO 2) = "11" ELSE '1';

  -- Sense keyboard rows with a multiplexer
  WITH d(1 DOWNTO 0) SELECT
    key_pressed <= NOT row(3) WHEN "11",
                   NOT row(2) WHEN "10",
                   NOT row(1) WHEN "01",
                   NOT row(0) WHEN OTHERS;
How can i simulate pressed key in test bench ? :|
 

elec4fun

Full Member level 3
Joined
Jan 24, 2005
Messages
159
Helped
38
Reputation
76
Reaction score
31
Trophy points
1,308
Location
Nice, France
Activity points
897
Hello,

You can simply do for example :

Code:
row(2) <= '0' when col(1) = '0' else '1';
That will simulate a button pushed between rwo(2) and col(1)....
 

zorro3k

Newbie level 4
Joined
May 4, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,331
It's error if I use "when" in test bench.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top