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.
Previous article:Portable test recorder designed with PIC microcontroller
Next article:PIC microcontroller programming basic format
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- A brief discussion on the bus differences of ARM Cortex-m0/m4 series
- Please help me interpret this article about tl431 bias current
- Disable automatic layer selection for routing
- [National Technology N32 MCU Development Package] --N32L40x Series
- Positive and negative 12V power supply, MC340463, simulation is OK, but the actual limit is about -5V
- [NUCLEO-WL55JC2 Review 4] STM32WL sub-GHZ RF (LoRa\FSK..)
- AVRDUDE released version 6.4 and moved to github
- Several issues on hysteresis compensation
- I wish you all good health and a safe family and a happy new year!!!
- MSP430FR2311 microcontroller infrared reflective sensing