Upload
ashlie-dennis
View
214
Download
1
Embed Size (px)
Citation preview
Advanced Digital CircuitsECET 146
Week 9
Professor Iskandar Hack
ET 221G, 481-5733
This Week’s Goals
Introduction to Keyboards Development of Scan Function Development of Decode Function Incorporating Keyboard into an example
design Lab 8 – Keypad to Seven-Segment-Display
Introduction to Keyboards
Almost always built from a array of rows and columns Most use momentary close push-button switches When a switch is closed this causes a short between
one column and one row Either the rows or columns are taken high (or low for
an active low system) one at a time and the lines for the columns or rows are monitored for a high (or low if active low system)
An Example Keyboard
Row Lines are on Pins 1-4 Column Lines are on Pins 5-8
What happens when a button is Pressed If the ‘6’ button is pressed then there will be a
short between the 2nd row (pin 2) and the 3rd column (pin 7)
Scan Function
The purpose of the scan function is to drive the input lines (we’ll use the rows as the inputs in this example) with a high during each clock cycle
Take the first row high Then 2nd row Then 3rd Last row Repeat cycle
Scan Function Designed in AHDL (note in cut and paste format)
SUBDESIGN scan( clk, reset : INPUT; scanlines[3..0] : OUTPUT;
)VARIABLE
ss: MACHINE OF BITS (scanlines[3..0])
WITH STATES ( s0 = B"0001", s1 = B"0010", s2 = B"0100", s3 = B"1000");
BEGIN ss.clk = clk; ss.reset = reset;
TABLE ss => ss;
s0 => s1; s1 => s2; s2 => s3; s3 => s0; END TABLE;END;
Note in this case I’m assigning theOutputs for each state in the declaration.Not always the most best for optimization,But makes the design a bit simpler.
Symbol for Scan Function
Decode Function
First of all it must look for a high on ANY of the four return lines (this are the rows in this example)
If any input is high then we know a key has been pressed. Then we look at what scan line is high and what return line are
high (note there will always a high scan line because of the way we designed the scan function) and decode what key has been pressed.
The decode function is unique for every keyboard and the way it’s used in the circuit – for example if we chose to have the scan lines go to the columns and the return lines go to the rows we would have a different table for the decode function.
We will have two four bit inputs for this function – scan and return. We’ll have a four bit output for the keycode and an one bit output for active keypress.
Decode Table Guidelines
First look at the keyboard layout and what keys are at each row/column position
For each position you’ll output that key value when that row/column position is high
You only have to include in the table the values for the row/columns of 1, 2, 4 and 8 since only one line can be high (we’re ignoring multiple key presses) at a time
Decode Table
Column
Value (scan)
Row Value (return)
KeyCode
1 1 1
1 2 4
1 4 7
1 8 CLEAR (10)
2 1 2
2 2 5
2 4 8
2 8 0
4 1 3
4 2 6
4 4 9
4 8 Help (11)
8 1 Up (12)
8 2 Down (13)
8 4 2nd (14)
8 8 Enter (15)
3rd column has a value of 4 and 3nd row hasa value of 4
Decode Function AHDL (cut and paste format)
SUBDESIGN decode( scan[3..0], return[3..0] : input;
keycode[3..0], keypress : output;)
BEGIN
TABLE scan[], return[] => keycode[], keypress;
x, 0 => 0, gnd; 1, 1 => 1, vcc;
1, 2 => 4, vcc; 1, 4 => 7, vcc; 1, 8 => 10, vcc; 2, 1 => 2, vcc; 2, 2 => 5, vcc; 2, 4 => 8, vcc; 2, 8 => 0, vcc; 4, 1 => 3, vcc; 4, 2 => 6, vcc; 4, 4 => 9, vcc; 4, 8 => 11, vcc; 8, 1 => 12, vcc; 8, 2 => 13, vcc; 8, 4 => 14, vcc; 8, 8 => 15, vcc;
END TABLE;END;
Symbol for Decode Function
Complete Keypad System
The complete system will have a scan function that will drive the columns (also go into the decode function) and the decode function
Of course you’ll need the keypad itself One important point – you will need to place pull-
down resistors on the return lines. Whenever there is no key pressed then the return
lines are floating (neither high or low), thus we need to place a 1K resistor between the return lines and ground to ensure that when there no connection to VCC (through the scan lines)
Altera Keypad Project Keypad and pull-down resistors are external from the Altera Part
Note the names of the nets and I/O
Symbol for Altera Keypad Project
Drawing of Connections between Altera and Keypad
Note – Pulldown Resistors
Lab 8 (Will be demonstrated – Don’t Do) Using the Keyboard data sheet on the next
page design a keypad system that will display whatever key is pressed (it will display 0 when no key is pressed)
Note that this keypad is different from the example, so the decode table will be different
Output ‘E’ for a # and ‘F’ for a * Save this project (no report due) for inclusion
in Lab 9
Keypad Data Sheet