Design of touch screen interface for intelligent instrument based on embedded technology

Publisher:静默思考Latest update time:2012-10-19 Source: 21IC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In modern production, in order to ensure the safe and reliable operation of mechanical equipment, it is usually necessary to use appropriate instruments and meters, use fault diagnosis technology to timely discover faults, and take reasonable maintenance or protection measures to eliminate faults and prevent and avoid accidents. Considering the size, portability and ease of operation of instruments, a large number of instruments and equipment in industrial fields such as coal, steel, metallurgy, electricity, and chemical industries have gradually chosen touch screens as system input devices.

In view of this situation, the author studied the touch screen input interface in the process of developing intelligent instruments for mechanical fault diagnosis. The interface circuit between the four-wire resistive touch screen and the PXA255 processor was designed, the design principle of the character device driver under the Linux framework was analyzed, the interface driver development of the touch screen was completed, and the MiniGUI user program using the touch screen as the input device was designed. The touch screen is used as the input device of the instrument, and the human-computer interaction is straightforward, which greatly facilitates the use of on-site operators.

1 Hardware structure and working principle

According to the working principle and transmission medium, touch screens are mainly divided into resistive, capacitive, infrared and surface acoustic wave types. The resistive touch screen is a 4-layer transparent composite film screen, as shown in Figure 1. The bottom is a base layer made of glass or organic glass; the top is a plastic layer with a hardened outer surface to make it smooth and scratch-resistant; in the middle are two metal conductive layers, and there are many small transparent isolation points between the conductive layers to separate the two layers. The two metal conductive layers are the working surfaces of the touch screen, and a silver glue is coated on both ends, which is called a pair of electrodes on the working surface of the touch screen. The X working surface and Y working surface of the four-wire touch screen are added to the two conductive layers respectively, with a total of 4 lead wires, which are connected to the X electrode pair and Y electrode pair of the touch screen respectively. When the stylus touches the screen, the two conductive layers touch at the contact point. When a resistive touch screen is used as an input device in conjunction with a display screen, its essence is to determine the touch point coordinates of the touch screen by measuring the voltage division of the resistors in the X and Y directions, and map the coordinates to the display screen coordinates, thereby achieving human-computer interaction. Since the working surface of the resistive touch screen is completely isolated from the outside world and is less affected by the environment, it has the advantages of being resistant to dust and water vapor, high stability, and no drift, and is particularly suitable for use in industrial sites.

Figure 1 Resistive touch screen structure

During the design process, ADS7843 was selected as the AD conversion chip for the touch screen interface. It has a 12-bit conversion accuracy and supports a maximum of 4 096 × 4 096 dot LCD, meeting the instrument design requirements.

The instrument system processor uses the Intel Xscale architecture PXA255 processor, and uses its GPIO port to simulate the SPI interface to communicate with the ADS7843. The interface principle is shown in Figure 2. The ADS7843 completes the switching of the acquisition channel and the acquisition of the voltage at the contact point. Its operation sequence mainly consists of control word input, voltage acquisition and analog-to-digital conversion. For details, see the reference. As long as the control word is sent to the D IN port according to the timing requirements in the driver, the acquisition result of the corresponding channel can be obtained from DOUT.

Figure 2 Interface circuit between ADS7843 and PXA255

2 Touch screen interface driver

The Linux driver is part of the system kernel. It separates software and hardware, provides communication interfaces for applications to access hardware, and manages and protects system hardware. The touch screen is defined as a character device under Linux. Its driver mainly completes the acquisition of contact voltage and transmits X coordinates, Y coordinates and pen action (press, lift or drag) data to the user space. When the stylus is pressed, the 11th pin of ADS7843 outputs a low level, triggering the 12th pin of the PXA255 general IO port to generate an external interrupt, start the timer, and realize the action of the touch screen. The driving process of the touch screen is shown in Figure 3.

Figure 3 Touch screen driver structure flow

2.1 Driver Writing

The touch screen driver is a character device driver under the Linux framework.

The driver entry function is ads7843_ts_init(), in which the I/O port is initialized, the pen interrupt and device node are registered, and the initialization work of the device file system to create a standard character device is completed [8-10]. The structure of the touch screen device operation is defined by ads7843_ts_fop s.

static struct file_operations ads7843_ts_fop s = {

read: ads7843_ts_read,

poll: ads7843_ts_poll,

ioctl: ads7843_ts_ioctl,

fasync: ads7843_ts_fasync,

open: ads7843_ts_open,

release: ads7843_ts_release,

};

In this way, the development of the device driver can be completed by simply correctly defining a few function procedures in the structure according to actual needs.

When the touch screen device is turned on, the ads7843_ts_open () function is first executed, and a buffer is initialized in the function to store coordinate data. After the touch screen is pressed, the system first triggers an interrupt. In the ads7843_ts_interrupt () interrupt program, the state of the in_timehandle global variable is determined. in_timehandle is changed in the timer function, that is, after entering the interrupt, the timer delays 20ms first, the software debounce of the touch screen is completed, and then it is determined whether the touch screen is pressed. Then, the read_xy () function is used to switch to the X and Y channels respectively, the AD conversion of the contact voltage is completed, and the 12-bit coordinate value is read.

static void ads7843_ ts_ interrup t ( int irq, void 3 dev_ id,

struct p t_regs3 regs)

{

sp in_lock_irq (&tsdevlock);

if ( in_timehandle > 0)

{

sp in_unlock_irq (&tsdevlock) ;

return;

}

disable_irq (IRQ_GPIO_ADS7843);

ads7843_ts_starttimer ( ) ;

sp in_unlock_irq (&tsdevlock) ;

}

When the application calls the read() function, it enters the driver's ads7843_ts_read() interface function. In this interface function, the sampling result is obtained, and it is determined whether the coordinates need to be calibrated. The final result is written into the buffer, and it is copied from the kernel space to the user space through the copy_to_user() function so that the application can use it. In the ads7843_ts_read() function, non-blocking operation is adopted, so that it returns immediately when no data arrives, and then the asynchronous trigger fasync() is used to notify the arrival of data. The ads7843_ts_poll() function is used for the non-blocking operation of the driver, and the ads7843_ts_fasync() function is used for the asynchronous trigger of the driver. The ads7843_ts_ioctl() function provides parameters that can be controlled from the user state, such as whether the touch screen is calibrated in the driver, the maximum and minimum coordinate values ​​of the screen, etc. The ads7843_ts_release() function is used to shut down the touch screen device.

2.2 Touch screen calibration

During the instrument development process, the touch screen is used as an input device in conjunction with the LCD. In order to make the coordinates obtained from the touch screen sampled correspond to the display coordinates of the screen, a mapping needs to be done, that is, the touch screen needs to be calibrated. As shown in Figure 4, the touch screen and LCD screen used are both standard rectangles. As long as they are installed properly, it can be considered that the X-direction coordinates of the touch screen are only related to the X-direction of the display screen, and the Y-direction coordinates are only related to the Y-direction of the display screen. Assuming that the resolution of the display screen is W ×H, the touch screen sampling coordinates corresponding to the upper left corner of the display area are (x1, y1), and the coordinates corresponding to the lower right corner are (x2, y2), then the corresponding relationship between the sampling coordinates (x, y) of any point on the touch screen and the display screen coordinates (xd, yd) can be calculated according to the following formula:

In this way, after measuring the sampling values ​​of the touch screen at points (x1, y1) and (x2, y2), the calibration function is compiled using the above formula. During the operation of the touch screen, the display coordinates corresponding to the actual touch points are calculated to complete the calibration of the touch screen.

Figure 4 Touch screen calibration

3 Touch screen user applications

The created Linux device file system touch screen node is /dev/ts. In the application, the device file can be opened with the open function like opening a file, and then the data passed from the driver to the user space can be read with the read() function. The instrument application is developed using MiniGUI, which is a lightweight graphical user interface support system developed by Beijing Feman Company and can be applied to real-time embedded systems. Its function interface is similar to Windows SDK, which is easy to develop.

The Input Abstract Layer (IAL) of MiniGU I provides rich support for input devices such as touch screen and mouse, and supports PXA255 processor platform. With simple settings, you can use the touch screen in the application. When configuring and installing MiniGU I, use the 22enable2px255bial item. Since the static compilation method of embedded resources is used when installing MiniGU I, before compiling, you need to create the mgetc2pxa1c file in the src/sysres/directory of MiniGU I, and use the following statement to set the system parameters in it to set the touch screen as an input device.

static char * SYSTEM_VALUES[ ] = { " fbcon" ," PX255B" , " /dev/ts" , " none" };

The way MiniGUI processes touch screen input is shown in Figure 5.

Figure 5 Touch screen input in MiniGUI

MiniGUI receives raw input data through the touch screen device driver and converts it into MiniGUI abstract touch screen events and data.

The relevant bottom-level event processing routine converts these touch events into upper-level touch messages and puts them into the corresponding message queue. The application obtains these messages through the message loop and passes them to the window procedure for processing. When compiling an application for a touch screen, all you need to do is call the corresponding statement to complete the expected operation when the window receives a touch screen message such as MSG_LBUTTONDOWN.

4 Conclusion

The embedded intelligent instrument touch screen interface enhances the human-computer interaction function of the instrument system and facilitates the use of operators; the modularization of the interface circuit and driver facilitates the subsequent improvement of the instrument and the development of new products, and can be transplanted and applied to various occasions as needed. The designed touch screen interface has been successfully applied in fault diagnosis and inspection instruments. It works stably and reliably and has good practical value.

Reference address:Design of touch screen interface for intelligent instrument based on embedded technology

Previous article:Application of MAX7219 in Transmitter Display
Next article:Design and simulation of bus LCD display announcement system based on Proteus

Latest Power Management 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号