Design and implementation of keyboard scanning module based on FPGA

Publisher:耿高良Latest update time:2010-08-12 Source: 国外电子元器件Keywords:FPGA Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In electronic products, keyboards are the most basic input devices. However, it is unrealistic to use general keyboard scanning devices in applications. A dedicated small keyboard needs to be designed separately. Modern EDA (electronic design automation) technology provides a good way to easily build a keyboard scanning module using VHDL hardware description language and FPGA devices. After actual operation, the module can scan and respond to each key action well and realize the pre-designed functions.

1 Overview

1.1 Universal keyboard and special keyboard

In modern personal computer systems, a universal standard keyboard (such as the standard 101/102 keyboard or the Microsoft Natural PS/2 keyboard) is generally used to implement the interface interaction between people and computers. All the required data, instructions and other information are entered into the computer through the keyboard.

However, in various embedded systems (such as mobile phones, microwave ovens, electric fans, etc.), the number of keyboard keys required is very limited, usually ranging from a few to a dozen (while standard keyboards usually have more than a hundred keys), and the functional meanings of each key are also different. Therefore, for each embedded system, the keyboard (including keyboard scanning module and related control signals, etc.) should be specially designed, and the various existing resources of the system should be fully utilized in combination with the actual engineering situation, so that the designed keyboard can be properly integrated into the embedded system and become an integral part of it.

1.2 Edit

Code keyboard and scan keyboard

In digital circuits, encoders can be used to directly encode key values. The output signal of each key is connected to each input terminal of the encoder. Through the encoding logic, the code value corresponding to each key can be obtained at the output terminal of the encoder. In the early days, this type of keyboard was called an encoding keyboard. However, when there are many keys, the cost of digital logic is high, and the direct encoding method is not flexible enough. Once the encoding logic is fixed, it is difficult to change.

On a general keyboard or when there are a large number of keys, a scanning method is generally used to generate key values. The keys are connected into a matrix, and each key is located at the intersection of a row and a column, as shown in Figure 1. The row and column of the pressed key are first determined by scanning, that is, the position code or scan code. Then the position code is converted into a key code value by looking up the table or the scan code is used directly. Some reference books call this a "non-encoded keyboard". However, this name can easily lead people to misunderstand that there is no corresponding key value, so it is also called a scanning keyboard.

Scanning keyboard [page]

1.3 Hardware Scanning Keyboard vs. Software Scanning Keyboard

If the scanning process is implemented by hardware logic, this keyboard is called a hardware scanning keyboard or an electronic scanning encoding keyboard. When performing keyboard scanning, it should be noted that there will often be some unavoidable mechanical jitters in the closing process of the key, which will cause the output signal to jitter, usually up to 10 ms to 20 ms wide. If the jitter area is not avoided, it may be mistaken for multiple key presses. Therefore, a hardware delay circuit should be set to delay the key value for tens of milliseconds before reading it. This circuit is called a de-jitter circuit. It should also be noted that when the current key value has not been sent out and another key is pressed, the subsequent key value will overwrite the previous key value, resulting in loss. Usually, a control signal can be set to allow the next key value to be generated only after the previous key value is sent out, or a group of registers can be set to save several previous key values, waiting for the system to process them one by one in sequence.

The advantage of hardware scanning keyboard is that the host does not need to bear the scanning task. Only when the key value is generated will an interrupt request be sent to the host. The CPU receives the key value in the corresponding interrupt mode, or the CPU obtains the key value from a certain address at a fixed time. This method greatly reduces the operating load of the CPU, allowing it to have more time to run other applications.

Of course, you can also execute the keyboard scanning program, and the CPU scans the keyboard through software methods. The process of the keyboard scanning program is shown in Figure 2. This kind of keyboard is called a software scanning keyboard. When a key is pressed, the keyboard makes an interrupt request to the host, and the software scans the keyboard to obtain the key value, or the CPU periodically executes the keyboard scanning program to obtain the key value. This scanning method is called row-by-row scanning. When a key is pressed, the column value of this key is first obtained, and then the row value of the key can be determined by scanning row by row, and the row and column values ​​are converted to the key value. Of course, a certain delay can be added during the keyboard scanning process to eliminate the impact of jitter.

Keyboard Scanner Flow

If the system has high requirements for the CPU's running speed, the CPU load is heavy, and the system resources are tight, you can set a single-chip microcomputer in the keyboard, which will execute the keyboard scanning program, and then request an interrupt from the CPU and send out the scan code or key value. Most common keyboards in modern computers use this keyboard scanning method. [page]

2 FPGA-based implementation method

2.1 Analysis of implementation methods

According to the actual needs of the project, the keyboard scanning module to be implemented should have the following characteristics:

The module writes the scanned key value information into the specified address of the memory in real time. The key value information includes the number of repetitions and key value of the same key. The system software reads the key value information from the address regularly to perform corresponding operations.

The method of keyboard debouncing is the multiple scanning method. When the same key value is scanned several times in succession, it is considered that the key is pressed, thus completing the debouncing operation.

Since this project does not require ASCⅡ character encoding keys, the key values ​​are designed to be sent directly from 1 to 20.

In order to indicate the operation of pressing a key for a long time, when it is determined that a key is pressed, it will be scanned once at a certain interval thereafter. If the same key value is obtained, the number of key repetitions will be increased by one, and the number of repetitions and the key value will be combined into key value information and sent out; scan again after a certain delay.

2.2 FPGA Implementation

The design uses four modules to implement the keyboard scanning function, namely the instant scanning module, the scanning control module, the scanning pulse module and the key value transmission module, as shown in Figure 3.

Functional module to realize keyboard scanning

2.2.1 Real-time scanning module

This module completes the keyboard instant scanning function. When a narrow pulse of the SCAN signal is detected, the module will generate a set of corresponding KB_OUT signals and output them to the keyboard matrix. Then the KB_IN input signal will be detected to determine whether any key is pressed and which key is pressed, and the corresponding instant key value VALUE will be sent out.

2.2.2 Scanning Control Module

The function of this module is to control whether scanning is allowed and whether keyboard debounce is completed. When no key is pressed, CTRL is set to a high level to allow scanning; when the same key is scanned several times in succession, it is considered that the key is pressed (the debounce operation has been completed). Then CTRL is set to a low level, scanning is prohibited and delay is started at the same time. When CNT reaches a certain value, scanning is restarted and delay is started again. At the same time, the number of key repetitions and the key value VALUE are combined into KEYVALUES and output. And so on, until no key is pressed or other key values ​​are detected.

2.2.3 Scan pulse module

The main function of this module is to generate scan indication narrow pulse and scan delay count. When CTRL is high, a SCAN narrow pulse is sent out at each rising edge of CLK 50Hz; when CTRL is low, the delay counter starts counting, and a scan pulse signal SCAN is sent out only when a certain value is reached.

2.2.4 Key-value transmission module

This module is responsible for writing key value information into the memory for periodic query by application software.

A memory write operation is initiated only when the value of YVALUES changes.

3 Conclusion

This module is implemented with VHDL hardware description language. After function and timing simulation, it is compiled with QUARTUS Ⅱ software and downloaded to Altera's CYCLONE 1C20 development board. After actual operation test on the keyboard, it is proved that this module can normally realize keyboard scanning and de-jittering functions, and can correctly identify the action of each key. At the same time, if the module is slightly modified, it can also be transplanted to other systems, which can greatly reduce the CPU operation load, which has a strong practical significance for most embedded systems that are sensitive to system resources.

Keywords:FPGA Reference address:Design and implementation of keyboard scanning module based on FPGA

Previous article:Design of Intelligent Command Line and Its Application in SOPC System
Next article:Universal Modem Based on SoPC and CORDIC Algorithms

Recommended ReadingLatest update time:2024-11-16 16:24

Design of multi-channel single-ended/differential signal acquisition system based on FPGA+DSP
In the process of signal processing, the method of DSP + FPGA collaborative processing is often used. This is because although DSP can achieve high-speed signal acquisition, its instructions are more suitable for implementing algorithms rather than logic control, and its external interface has poor versatility. FP
[Embedded]
Design of multi-channel single-ended/differential signal acquisition system based on FPGA+DSP
LED display screen control solution based on FPGA
As an important medium for modern information release, LED (Light Emitting Diode) large screens are receiving great attention from all walks of life, especially the business and advertising sectors, and are widely used in the fields of industry, transportation, commerce, advertising, finance, sports competitions, si
[Power Management]
LED display screen control solution based on FPGA
The main differences between MCU, PSOC and FPGA
  The current single-chip microcomputer is generally MCU + limited fixed analog or digital peripherals; FPGA is a programmable digital peripheral circuit; PSoC is equivalent to MCU + programmable analog peripheral circuit + programmable digital peripheral circuit. The   biggest feature of PSoC is its high integration
[Microcontroller]
Research on FPGA testing method based on test system
1 Introduction At present, most FPGAs use the technology based on lookup tables, which are mainly composed of programmable input/output units (IOBs), programmable logic units (CLBs), programmable routing resources (PI), SRAM for configuration, BlockRAM and digital delay-locked loops (DLLs). To test FPGAs, it is nece
[Test Measurement]
Research on FPGA testing method based on test system
Data Communication between CY7C68013 and FPGA
 Universal Serial Bus (USB) has the advantages of fast, bidirectional, large-volume transmission, low cost and hot-swappable. One of Cypress's FX2 series chips, CY7C68013, is the first microcontroller that complies with the USB2.0 standard. It integrates a USB2.0-compliant transceiver, a serial interface engine (SIE),
[Analog Electronics]
Data Communication between CY7C68013 and FPGA
Design of high-speed real-time data transmission system based on FPGA
introduction The rapid development of the information age has urged all kinds of data information to be transmitted at a faster pace. People require information to be transmitted faster and faster, and at the same time, they also require information to be transmitted more timely. Therefore, high-speed and real-
[Embedded]
Design of high-speed real-time data transmission system based on FPGA
TMS320C61416 Control FPGA Data Loading Design (I)
At present, there are usually two methods to achieve loading: one is to use a dedicated cable to load data through the JTAG port, and the other is to plug in the PROM chip that matches the FPGA manufacturer. The former requires running a dedicated loading software on the PC and downloading it directly to the FPGA chip
[Analog Electronics]
TMS320C61416 Control FPGA Data Loading Design (I)
Design of human-computer interaction system based on single chip microcomputer and FPGA
In the development of modern instruments, human-computer interaction functions are playing an irreplaceable role. Instruments with user-friendly human-computer interaction interfaces will be easier to operate and use, thereby improving work efficiency. Liquid crystal displays (LCDs) have the characteristics of low p
[Microcontroller]
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号