120 likes | 405 Views
Keypad BFM. +5V. Key pressed. ROW[0]. X. ROW[1]. ROW[2]. R2. R1. R1. R1. R2. R2. R2. R1. ROW[3]. +5V. COL[3]. COL[0]. COL[1]. COL[2]. 5V 0V. R. ?. Keypad BFM. module keypad (ROW, COL); input [3:0] ROW; output [3:0] COL; …. Keypad BFM (cont.). parameter R1 = 8200;
E N D
+5V Key pressed ROW[0] X ROW[1] ROW[2] R2 R1 R1 R1 R2 R2 R2 R1 ROW[3] +5V COL[3] COL[0] COL[1] COL[2] 5V0V R ? Keypad BFM module keypad (ROW, COL); input [3:0] ROW; output [3:0] COL; …
Keypad BFM (cont.) parameter R1 = 8200; parameter R2 = 220; parameter C = 0.025; initial begin for (i = 0; i < 16; i = i+1) begin keystate[i] = 0; end on_delay = R2*C*(0.51); off_delay = R1*C*(0.51); end buffers buffs (COL, new_col);
Keypad BFM (cont.) // bitwise ands assign new_col[3:0] = ~( ({4{(ROW[0] === 1'b0)}} & keystate[3:0]) |({4{(ROW[1] === 1'b0)}} & keystate[7:4]) |({4{(ROW[2] === 1'b0)}} & keystate[11:8]) |({4{(ROW[3] === 1'b0)}} & keystate[15:12]) ); wire row_test = (ROW[3] === 1'b0); // not used
Keypad BFM (cont.) // keys task to define key states // for 16 keys of keypad task keys; input [3:0] key_no; input pressed; begin keystate[key_no] = pressed; end endtask endmodule
Pressing a Key w/the BFM Assume module keypad has instance name kp1. Then, somewhere in the test module… `define tb test_bench `tb.kp1.keys(4,1); //press 4th key `tb.kp1.keys(4,0); //release 4th `tb.kp1.keys(9,1); //press 9th key `tb.kp1.keys(9,0); //release 9th `tb.kp1.keys(7,1); `tb.kp1.keys(14,1);
Scanner Logic • Column signal rising delay is long due to pullup and switch+input buffer capacitance • Ghosting is possible if you sample keys too early… • LFSR counter provides ghosting and debounce delay
Scanner Logic (2) • Scanning stops after key is debounced • KEY_RDY signal is asserted • KEY_RDY signal handshakes with KEY_RD_
Scanner Logic (3) • KEY_DATA is updated at the point of key debounce complete • KEY_DATA is driven to target system with encoded key data corresponding to pressed key while KEY_RD_ is asserted • Auto_read module generates KEY_RD_ read strobe when KEY_RDY is asserted • By connecting AUTO_RD_ to KEY_RD_, key data is automatically read after a key has been detected • Scanning resumes after key is read by host system
Using the Keypad BFM • Rows are sequentially driven either 0 or “z” • Columns are either “1” from pullup when no key is pressed or… • “0” when key is pressed at intersection of row and column • keystate register defines pressed keys…
Using the Keypad BFM (2) • BFM allows modeling multiple asserted keys • keystate is declared as 16 bit register - bits are assigned value of “one” when key is pressed • Bit 0 of 16-bit register corresponds to row/col 00/00 • Key positions 0-3 are on first row (row 0), key positions 4-7 are on second row (row 1), etc.
The End!