Teclado
Teclado
Teclado
1. The keyboard checks to ensure that both the clock and keyboard lines are
inactive. Inactive is indicated by a High state. If both are inactive, the keyboard
prepares the 'start' bit by dropping the data line Low.
2. The keyboard then drops the clock line Low for approximately 35us.
3. The keyboard will then clock out the remaining 10 bits at an approximate
rate of 70us per clock period. The keyboard drives both the data and clock line.
4. The computer is responsible for recognizing the ‘start’ bit and for receiving
the serial data. The serial data, which is 8 bits, is followed by an odd parity bit
and finally a High stop bit. If the keyboard wishes to send more data, it follows
the 12th bit immediately with the next ‘start’ bit.
This pattern repeats until the keyboard is finished sending data at which point
the clock and data lines will return to their inactive High state. In Figure 10.1
the keyboard is sending a scan code of 16 for the "1" key and it has a zero
parity bit.
When implementing the interface code, it will be necessary to filter the slow
keyboard clock to ensure reliable operation with the fast logic inside the FLEX
chip. Whenever an electrical pulse is transmitted on a wire, electromagnetic
properties of the wire cause the pulse to be distorted and some portions of the
pulse may be reflected from the end of the wire. On some PS/2 keyboards and
mice there is a reflected pulse on the cable that is strong enough to cause
additional clocks to appear on the clock line.
Here is one approach that solves the reflected pulse problem. Feed the PS/2
clock signal into an 8-bit shift register that uses the 25Mhz clock. AND the bits
of the shift register together and use the output of the AND gate as the new
"filtered" clock. This prevents noise and ringing on the clock line from causing
occasional extra clocks during the serial-to-parallel conversion in the FLEX
chip.
A few keyboards and mice will work without the clock filter and many will not.
They all will work with the clock filter, and it is relatively easy to implement.
This circuit is included in the UP1cores for the keyboard and the mouse.
As seen in Figure 10.2, the computer system or FLEX chip sends commands to
the PS/2 keyboard as follows:
1. System drives the clock line Low for approximately 60us to inhibit any new
keyboard data transmissions. The clock line is bi-directional.
2. System drives the data line Low and then releases the clock line to signal
that it has data for the keyboard.
3. The keyboard will generate clock signals in order to clock out the remaining
serial bits in the command.
4. The system will send its 8-bit command followed by a parity bit and a stop
bit.
5. After the stop bit is driven High, the data line is released.
Each key sends out a make code when hit and a break code when released.
When several keys are hit at the same time, several make codes will be sent
before a break code.
Interfacing to the PS/2 Keyboard Port 165
The keyboard powers up using this scan code as the default. Commands must
be sent to the keyboard to use other scan code sets. The PC sends out an
initialization command that forces the keyboard to use the other scan code.
The interface is much simpler if the default scan code is used. If the default
scan code is used, no commands will need to be sent to the keyboard. The keys
in Table 10.3 for the default scan code are typematic (i.e. they automatically
repeat the make code if held down).
166 Rapid Prototyping of Digital Systems Chapter 10
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY keyboard IS
PORT( keyboard_clk, keyboard_data, clock_25Mhz ,
reset, read : IN STD_LOGIC;
scan_code : OUT STD_LOGIC_VECTOR( 7 DOWNTO 0 );
scan_ready : OUT STD_LOGIC);
END keyboard;
ARCHITECTURE a OF keyboard IS
SIGNAL INCNT : STD_LOGIC_VECTOR( 3 DOWNTO 0 );
SIGNAL SHIFTIN : STD_LOGIC_VECTOR( 8 DOWNTO 0 );
SIGNAL READ_CHAR : STD_LOGIC;
SIGNAL INFLAG, ready_set : STD_LOGIC;
SIGNAL keyboard_clk_filtered : STD_LOGIC;
SIGNAL filter : STD_LOGIC_VECTOR( 7 DOWNTO 0 );
BEGIN
PROCESS ( read, ready_set )
BEGIN
IF read = '1' THEN
scan_ready <= '0';
ELSIF ready_set'EVENT AND ready_set = '1' THEN
scan_ready <= '1';
END IF;
END PROCESS;
This process filters the raw clock signal coming from the
keyboard using a shift register and two AND gates
Clock_filter:
PROCESS
BEGIN