![]() |
Kinetis SDK v.1.2 Demo Applications User's Guide
Rev. 0
Freescale Semiconductor, Inc.
|
This demo application demonstrates how to use PDB to trigger ADC and measure on-board thermistor.
This lab shows how to configure and use the ADC module to sample the differential voltage across on-board thermistors RT1-RT4. If the user touches any on-board thermistor with a finger, the lab application detects a change in the thermistor temperature and starts flashing the corresponding LED pair.
This Tower System module is supported by the Thermistor Lab demo.
-TWR-KV10Z32
For detailed instructions, see a Kinetis SDK User's Guide for your board.
The lab application configures both ADCs to be triggered by the FlexTimer0 via the PDB. The FlexTimer is configured to generate the 16 KHZ PWM and the channel1 trigger is used to trigger both ADCs via the PDB. The PDB is configured to generate four delayed trigger signals to both ADCs per FlexTimer0 Channel 1 trigger and, as a result, 4 ADCs samples are converted per each Flextimer channel trigger. The ADC is configured to be in a 16-bit differential and ping-pong mode.
When an ADC conversion is complete, an interrupt is generated by the ADC module and an interrupt service routine is executed. The interrupt service routine ADCn_ISR() calls the ADCn_Task which executes these tasks:
reads ADC results registers. filters ADC results with low-pass FIR filter. differentiates filtered results to detect a change in a voltage across the thermistor. detects a negative/positive slope of a voltage change to determine which LED will be turned on/off. executes a software timer, whose time out period is 100ms and it resets every 400ms. the software timer is used to generate a time base for LEDs flashing.
To measure a voltage across the thermistor, configure the ADC for a differential mode of operation. In a differential mode, the ADC measures a difference between two analogous inputs. The ADC enables selecting input pairs which are treated as differential inputs.
If a user places a finger on a thermistor, its temperature increases. The temperature rise results in a voltage decrease across the resistor. If the user removes the finger, the temperature decreases and the voltage goes up.
A simple differentiators are used to detect a voltage change. The filtered thermistor voltage is stored in a buffer. The buffer size is defined by the BUFF_SIZE. The differentiator calculates a difference between an actual voltage sample and a sample delayed by i_delay pointer, which points to the buffer.
If the voltage across the thermistor decreases, the differentiator returns a negative value. If the voltage increases, the differentiator returns a positive value. If there is no change in voltage, the deviator output returns zero. The bigger the slope of voltage increase/decrease, the more positive/negative value the differentiator returns. The lab application uses this information to detect if the finger is placed on the particular thermistor or if the finger was removed. Placing/removing a finger on the thermistor is characterized by a certain slope (rate) of voltage decrease/increase. The application defines positive and negative thresholds for each thermistor. If a difference output exceeds threshold limits(for at least three consequent samples), an action is taken and a corresponding LED starts to flash.