Let's first consider the origin of these aspects. Take capacitive touch sensing, for example. When touch-sensitive keys were first introduced, designers quickly realized that it wasn't as simple as implementing traditional push buttons. Touch keys must be handled in the same way as analog sensors. Radiated noise, or noise that can be conducted from environmental sources such as household appliances, compact fluorescent lamps, power supplies, mobile phones, and motors, requires careful management. To achieve robust and functional keys, software techniques such as contour detection, filtering, debouncing filters, and slew rate control, as well as good signal acquisition routing, must be applied. Currently, the need to regenerate a segmented or graphic LCD when user input is received must be added to this human interface system. Recreating graphical constructs, such as geometric shapes or text, on a TFT or OLED display has historically required the bandwidth of a processor. It is also important to consider human interface applications that incorporate touch screen inputs in addition to the graphic display and touch keys, as in the thermostat in Figure 1. Finally, a communication interface such as USB will generally also be required.
The challenge, therefore, is to enable real-time processing of user input from touch keys, a touchscreen sensor, and USB data communication, as well as display updates. The solution falls into two fundamental categories for the underlying hardware and software.
Hardware Implementation:
Some microcontrollers combine an LCD controller and touch-sensing peripherals on a single chip, but the LCD controller typically manages a segmented display rather than a graphic LCD.
The latest generation of microcontrollers, such as the PIC24FJ256DA210 shown in Figure 2, takes integration to a new level by combining a graphics display controller, a USB 2.0 On-The-Go peripheral, and a special analog peripheral that can be used for touch sensing. To support graphics displays, the PIC24FJ256DA210 incorporates a color lookup table, a large 96KB of RAM, a graphics processing unit (GPU), and a direct interface to STN, TFT, and OLED displays. The large onboard RAM allows for the storage of 256-color graphics data at 8 bits per pixel, enabling a 320x240 QVGA display within the chip's integrated RAM. The color palettes used in the color lookup table can also be switched to use different sets of rectangles, ASCII text, and PNG image decompression for recreation with a single command. This reduces CPU usage to 0%.
Figure 2 also shows the Charge Time Measurement Unit (CTMU) analog peripheral. Capacitive touch sensing is one of many applications offered by the CTMU. The CTMU provides a constant current source with a timer that can be used to charge a sensor panel. The panel's voltage can be measured using the analog-to-digital converter (ADC). When the user places a finger on the panel, the change in capacitance is registered as a voltage change by the ADC. In its simplest implementation, each ADC channel can be connected to a touch key input. With 24 ADC channels, the PIC24FJ256DA210 provides enough capacitive touch channels to meet the needs of most applications.
Another hardware consideration is necessary. If the application has a resistive touchscreen input and touch keys, the graphic LCD is overloaded with a resistive touchscreen sensor for quick menu access. If the touchscreen controller is integrated into the main microcontroller, the touchscreen sensor outputs, which typically have 4 or 5 wires, can be connected to the microcontroller's analog channels. In this case, the microcontroller's A/D converter resources are shared between the touch key and touchscreen functions. The A/D converter measurements are used to estimate the XY coordinates detected on the touchscreen.
Software Implementation:
Generally, the firmware for the graphics display drivers and the capacitive touch sensing will be available as separate libraries. Effective integration of these libraries requires a main routine that essentially functions as a Real-Time Operating System (RTOS) to establish the priorities and service frequency for each task. For tasks that share common hardware resources, the main routine also needs to establish a mechanism for non-destructively updating the control and data loggers for the shared resource before switching between tasks. In the previous example, both the touchscreen sensors and the touch keys feed the A/D converter. The A/D converter's sampling rate, the channels to be sampled, and the number of samples required differ depending on the touchscreen sensor and the keys. Therefore, the main routine needs to save these parameters before switching between two tasks.
Since the user can provide input via both the touchscreen and the touch keys at any time, the main routine may need to establish a time division to allow both sensors to scan frequently enough. The display may require periodic updates if, for example, the application is rendering animated graphics on the screen.
If the display is only updated when the user makes menu selections, then there is no CPU resource contention between touch sensing and display controller functions. The example device (PIC24FJ256DA210) has dedicated hardware for graphics acceleration, so time division between touch and graphics functions is no longer an issue. On this device, rendering a box, line, or ASCII text requires only one CPU-generated command. A demonstration project is available that shows the integration between the touch keys, the touch screen sensor, and the graphic display using the underlying software libraries. It can be downloaded free of charge with the mTouch™ Capacitive-Touch library and can be run on the PIC24FJ256DA210 development board shown in Figure 3.
There are other functions that can be integrated onto a single chip along with touch sensing. For example, the CTMU peripheral can be used for temperature measurement in medical instrumentation, timekeeping, and other functions. In an application such as a thermostat, the CTMU peripheral can be used for both temperature measurement and touch sensing, using an external diode. Since temperature measurement is only required infrequently, this peripheral can be used for both functions.
USB Communications
Integrating USB and touch sensing is relatively straightforward if a few simple rules are followed. When the application connects to a USB host, it goes through an enumeration phase during which CPU bandwidth is heavily dedicated to performing the USB function. The touch sensing functions should be reset within a couple of minutes after the enumeration phase is complete. Once enumeration is complete, the USB functions consume a very small amount of CPU bandwidth, typically less than 2%. At this point, the main routine can choose to service the USB receiver function periodically, approximately every millisecond, or switch to a more interrupt-driven method.
Many applications with touch interfaces have begun to incorporate haptic feedback. Integrating haptics into an application is more than just a mechanical challenge. Haptic feedback typically requires a simple Pulse Width Modulation (PWM) peripheral to control a small vibrator or motor. It is likely that, in some applications, the integrated PWM peripheral will also be used to drive an audio speaker. In such cases, effective integration may require separate time bases for the PWM channel controlling the haptic motor and the one controlling the audio speaker.
Conclusion:
While integrating the graphic display and touch sensing functions onto a single chip reduces system costs, software complexity can significantly impact time to market. Implementation is simplified by selecting a microcontroller platform that supports graphics libraries, USB, and touch sensing software designed and tested for interoperability and proven robust integration.
Author: Rishi Vasuki, Director of Product Marketing,
Advanced Microcontroller Architecture Division, Microchip Technology.

