Interface Design between Touch Sensor QST108 and PIC Microcontroller

Publisher:upsilon30Latest update time:2011-09-29 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Interface Design between Touch Sensor QST108 and PIC Microcontroller

1 Overview

QST108 is a capacitive touch sensor launched by STMicroelectronics for touch button control of human-machine interface.

Its working principle adopts the patented charge transfer capacitor technology (QProx) of Quantum Corporation of the United States, supports 8 independent buttons, and can choose two normal working modes: button state detection output or I2C bus control; at the same time, it can enter low power mode through software commands and can be awakened when a button is pressed. The unique adjacent button suppression algorithm of QST108 makes other buttons in an invalid state when a button is pressed but not released; the self-calibration and automatic drift compensation functions make it unnecessary to calibrate manually, thus further reducing the application difficulty of QST108. The pin configuration is shown in Figure 1, and the functions of each pin are listed in Table 1.


2 How QST108 works

2.1 Key state detection output method

QST108 has two normal working modes: key state detection output and I2C bus control. The high and low levels of pin OPT1 determine the specific working mode of QST108: high level, working in key state detection output mode; low level, I2C bus control mode. When working in key state detection output mode, the state of the 8 keys is determined by the level of pin OPT6, and is output directly or in BCD code through pins KOUT1~KOUT8. Among them, the BCD code mode only uses pins KOUT1~KOUT4. Since this operating mode is relatively simple, this article only discusses in detail the interface design and precautions of QST108 working in I2C bus control mode with PIC microcontroller.

2.2 I2C bus control method

In this mode, QST108 is connected to the microcontroller via the I2C bus. QST108 acts as a slave, and the input levels of pins OPT4, OPT3, and OPT2 determine the lower 3 bits of the slave address of QST108 on the I2C bus. The upper 4 bits of the address are fixed to 0101. Software settings can provide maximum flexibility in the use of QST108. Five pins can be provided as general output ports.

3 Main operation commands of QST108

When QST108 works in I2C bus control mode, various control commands are mainly sent to QST108 through I2C bus protocol, including initialization setting commands, QST108 key status readout commands, etc. Operation commands are divided into short command frames and extended command frames according to their length. Considering that the former can complete the normal operation of QST108, this article only introduces short command frames. Its data format is listed in Table 2, and common commands are listed in Table 3. Note that when QST108 receives different commands, it will give different response frame structures.

When the command is a short frame structure, the highest bit of the first byte of the command frame is 1 to distinguish it from the extended command. The command ID is the command number, which consists of 5 bits of data and is used to distinguish different commands; the parameter bit is only 1 bit. When this bit is 1, it means that the command has a 1-byte parameter. If it is 0, the command has no parameter and no checksum byte; the check bit is used to generate odd parity. Note that this check bit is only for the first byte of the command frame (that is, the number of "1" in the first byte of the command frame is an odd number); the 8-bit checksum is the lower 8 bits of the cumulative sum of the first 2 bytes of the command frame.

If QST108 fails to receive the command correctly or receives an illegal command, it will give a unified response frame (containing only one byte) containing an error code, as shown in Table 4. For QST108, the response data frame structure corresponding to the read touch key status command is shown in Table 5.

As shown in Table 4, the error frame has only one byte of data, and the check bit provides a simple basis for judging whether the data is received correctly. The error code has 6 bits in total, which are used to distinguish different errors. For example, the error code is 0x01, which means that QST108 received an illegal command; the error code is 0x11, which means that the checksum of the received command is wrong, etc.

It can be seen from Table 5 that the length of the response frame is 4 bytes. SCK1~SCK8 represent the state of the touch key respectively. 1 means the corresponding key is pressed, and 0 means the corresponding key is not pressed. The last byte is the checksum, which is the low 8 bits of the cumulative sum of the first 3 bytes of the response frame. It should be emphasized that only the low 3 bits of the key error code are valid: bit 0 indicates that QST108 is in the calibration state; bit 1 indicates whether the current accumulated number of key presses has reached the maximum number of keys provided by the device, and 1 means the maximum number has been reached; bit 2 indicates whether the minimum number of key presses has been reached. At the same time, it is also necessary to distinguish whether the response frame sent by QST108 is an error frame or a normal response frame structure given by the correct command. The method is very simple. When the software reads the first byte of the response frame, it judges its highest bit: if it is 0, it means a normal response; if it is 1, it means that the received frame is an error frame. At this time, the host only needs to generate a stop bit and perform error processing or stop the operation.

4 Interface circuit between QST108 and PIC

Figure 2 shows the practical circuit design of touch key detection based on QST108 and PIC microcontroller. QST108 communicates with PIC through I2C bus, and the interface is simple. The key input part refers to the design method of the typical application circuit diagram given in its data sheet. The microcontroller uses PIC16F877A, which has rich on-chip resources and the MSSP module supports the I2C bus protocol, which is very convenient for controlling QST108. The IRQ pin of QST108 is connected to the external interrupt input pin RB0 of PIC16F877A. Since the IRQ pin is an open-drain output, a pull-up resistor must be connected. When a key is pressed, the IRQ pin changes from high to low, triggering the PIC16F877A to generate an external interrupt. The microcontroller sends a command to read the key status to determine which key is pressed, and then performs different processing according to different keys.

5 Software Design

The software part includes the initialization of PIC16F877A and QST108, the touch key detection subroutine, the interrupt program of the microcontroller, and the program for various processing according to the key detection results. Due to space limitations, this article only gives the subroutine for PIC16F877A to read the key status. Assuming that the device address of QST108 is 0, the program is as follows:

Conclusion

This article focuses on the working mode of the capacitive touch sensor QST108, the main operation commands, and the interface design between QST108 and PIC microcontroller. QST108 allows users to design 8-key capacitive touch panels with ordinary or flexible printed circuit boards, so conductive ink can be printed on the circuit board as sensing electrodes; QST108-based applications require very few external components, and only 1 sampling capacitor and 1 resistor are required for each channel. Due to these characteristics, QST108 is very suitable for use in intelligent control interfaces that can respond to user touch.

Reference address:Interface Design between Touch Sensor QST108 and PIC Microcontroller

Previous article:Portable test recorder designed with PIC microcontroller
Next article:PIC microcontroller programming basic format

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号