Table of Contents
The FRDM-KL46Z from Freescale comes with various features on it. One of the features is a capacitive touch sensing input module. NXP-Freescale provides a software library to run the touch sensor, but this tutorial will go over how to use it without the libraries. The touch sensing software can be found here. For this tutorial we will be using Keil 5.18a.
Getting Started with Freescale's Freedom KL46Z Development Board - A good tutorial for first time users.
KL46P121M48SF4RM.pdf - Reference Manual for Chip
FRDM-KL46Z_UM.pdf - User Manual for Board
The initialization sets the necessary registers TSI module to run the touch sensor. The TSI module has three registers the General Control and Status Register (GENCS), the DATA register, and the threshold register (TSHD). The DATA register isn't used in the initialization; it is only needed to access the data and needs nothing to be initialized. In the GENCS register controls the TSI and how it operates. The user can decide to operate in one of four modes, the first just reads capacitance, the next two work on reading a certain threshold, and the last is for noise detection. The range and overall configuration is controlled by the REFCHRG, DVOLT, EXTCHRG, PS, and NSCN. Changes these values will change the range that the touch sensor reads and outputs. The enable bit is set with TSIEN_MASK. STM_MASK is necessary to be set to 1 if a hardware trigger is desired, since we are using a software trigger, we will not set it. The ESOR_MASK is not set, so that we use an out of range interrupt. If it is set, an interrupt will be sent at the end of a scan. The SCNIP flag is not set because it is read only. It signals when a scan is in progress.
The Threshold register is not used in this application, because we are operating in the first mode. If we would use mode 2, 0100, or mode 3, 1000, we would need to set the register. TSHD is split into two half words. The upper threshold and lower threshold.
This function works by select one of the two channels on the board. This one is channel 10. Channel 10 reads the capacitance from low to high. The first thing needed after that is to set the software trigger to start a scan. After the scan is complete we then read the data. After getting the data we reset the end of scan flag, so that we may run another scan later. We return our scan data minus a desired offset.
This function works the same way as Touch_Scan_LH, but instead of using channel 10 it uses channel 9. Channel 9 reads the capacitance as high to low from left to right.
SCAN_OFFSET - This is an offset for for the scan result. This allows a larger range, but keeps the start at 0.
SCAN_DATA - This is a quick way of getting the data that is stored in TSI0_DATA_TSICNT.
This can be used for many different applications, but a helpful one for seeing what values you are getting is one displaying the value on the LCD screen. The main code shown below uses the LCD code given here.