Defines | Functions

mTouch.c File Reference

Implements the post-acquisition filtering and decoding of the mTouch sensors. More...

#include "mTouch.h"
Include dependency graph for mTouch.c:

Go to the source code of this file.

Defines

#define MTOUCH_SENSOR_state   (*sensor).state
#define MTOUCH_SENSOR_timer   (*sensor).timer
#define MTOUCH_SENSOR_debounce   (*sensor).debounce
#define MTOUCH_SENSOR_timeout   (*sensor).timeout

Functions

void mTouch_Init (void)
 Main initialization routine for all mTouch framework modules including the built-in communication module, if enabled.
void mTouch_Decode (void)
 Updates the state of each active-mode sensor using the latest acquisition value.
void mTouch_UpdateBaseline (void)
 Updates the baseline for the given sensor with the given value.
void mTouch_ChangeState (void)
uint8_t mTouch_ButtonStateMachine (void)

Variables

Global Sensor Variables

These variables store information about the current state of the sensors. They should only ever be updated by the mTouch framework, but may be read globally so that special actions can be taken based on the sensors' status. Refer to the mTouch.h file for more information about these variables.

mTouch_State mTouch_state
 Tracks the state of the mTouch algorithm.
mTouch_StateVariables mTouch_stateVars
 Stores all state-temporary variables to be reinitialized each mode change.
uint16_t mTouch_average [MTOUCH_NUMBER_SENSORS]
 Array to track the unpressed value of each sensor.
Constant Threshold Arrays

These arrays are stored in program memory at compile time, so they do not require RAM. The downside to this implementation is that their values cannot be updated at runtime. If this is something your application requires, further editing will be needed.

const uint16_t mTouch_pressThreshold [MTOUCH_NUMBER_SENSORS] = PRESS_THRESHOLD_INIT
 Constant array containing the press threshold for each sensor.
const uint16_t mTouch_releaseThreshold [MTOUCH_NUMBER_SENSORS] = RELEASE_THRESHOLD_INIT
 Constant array containing the release threshold for each sensor.

Detailed Description

Implements the post-acquisition filtering and decoding of the mTouch sensors.

Definition in file mTouch.c.


Define Documentation

#define MTOUCH_SENSOR_debounce   (*sensor).debounce
#define MTOUCH_SENSOR_state   (*sensor).state
#define MTOUCH_SENSOR_timeout   (*sensor).timeout
#define MTOUCH_SENSOR_timer   (*sensor).timer

Function Documentation

uint8_t mTouch_ButtonStateMachine ( void   )

Initialization State

The default state of all sensors on power up. Once sensors leave this state, they do not return. Initialization begins by decrementing the timer variable for the sensor. If timer has not yet reached 0, the areInitialized and allReleased flags are cleared to prevent any advanced decoding logic, such as sliders and wheels, or communications from occuring. Once timer reaches 0, the sensor transitions to the MTOUCH_RELEASED state, the debounce counter is reset to the value needed to enter the pressed state, and the baseline is updated to equal to the current sensor value.

Released State

This state can be entered from either the MTOUCH_INITIALIZING or MTOUCH_PRESSED state. The only way to leave this state is by creating enough consecutive positive shifts of the reading above the baseline to overflow the debounce variable for the sensor. Once this is done, the sensor will enter the pressed state.
The code for this section begins by checking to see if the latest reading is greater than the baseline by at least the press threshold. If it is, the debounce variable is decremented. Once the debounce value has been reached 0, the sensor will change to the MTOUCH_PRESSED state, reset the debounce counter, initialize the press timer (if enabled), toggle the toggle bit, and clear the 'allReleased' flag.
If the threshold has not been crossed, the debounce counter is reset to the initial press debounce value and the baseline is updated.

Note:
This is the only state and condition where the baseline is able to be updated, and we only use the latest reading to update the baseline once we know it's not crossing any thresholds.

Pressed State

A sensor can only enter this state from the MTOUCH_RELEASED state, but there are two ways to leave: First, by being in the state for too long and allowing the press timer to run out. Second, by having a the delta value smaller than the release threshold on enough consecutive scans to cause the debounce counter to reach 0.

The code for this section begins by decrementing and checking the timer variable to see if it has reached 0. If so, the sensor transfers to the MTOUCH_RELEASED state, the debounce counter is reset and the baseline is re-initialized to the sensor's current reading. The baseline is reset to allow for a quick recovery if some environmental condition caused the sensor to become stuck. See the NEGATIVE_CAPACITANCE configuration option for the different behaviors that can be implemented to quickly allow the baseline to re-settle to the unpressed value.

If the timer has not yet reached 0, the reading is checked against the release threshold. If the difference between the sensor's reading and the baseline (delta) is less than the release threshold, the debounce variable is decremented in the same manner as the press timer. When it reaches 0, the sensor enters the MTOUCH_RELEASED state and the debounce counter is set to debounce value required to enter the pressed state. If it has not crossed the threshold (meaning: the delta value is still large enough to register as a press), the debounce counter is reset to the release debounce value.

Note:
The baseline is never updated while the sensor is pressed so the system can remember where the unpressed value should end up. Because of this, the baseline can be better thought of as a released-state average.

Definition at line 579 of file mTouch.c.

Here is the caller graph for this function:

void mTouch_ChangeState ( void   )
void mTouch_Init ( void   )

Main initialization routine for all mTouch framework modules including the built-in communication module, if enabled.

Framework Initialization Notes

1. Loop through all enabled, active sensors and initialize their variables.

2. Loop through all enabled sliders and initialize the slider's output value.

3. Initialize mode variables and flags

4. Initialize non-array system variables

5. Initialize the DACOUT pin when it is used as a guard ring.

6. Initialize the ADC module for mTouch operation.

7. Initialization complete - enable active-mode mTouch scanning.



Definition at line 258 of file mTouch.c.

Here is the call graph for this function:


Variable Documentation

uint16_t mTouch_average[MTOUCH_NUMBER_SENSORS]

Array to track the unpressed value of each sensor.

Definition at line 86 of file mTouch.c.

const uint16_t mTouch_pressThreshold[MTOUCH_NUMBER_SENSORS] = PRESS_THRESHOLD_INIT

Constant array containing the press threshold for each sensor.

Definition at line 184 of file mTouch.c.

const uint16_t mTouch_releaseThreshold[MTOUCH_NUMBER_SENSORS] = RELEASE_THRESHOLD_INIT

Constant array containing the release threshold for each sensor.

Definition at line 185 of file mTouch.c.

Tracks the state of the mTouch algorithm.

Definition at line 84 of file mTouch.c.

Stores all state-temporary variables to be reinitialized each mode change.

Definition at line 85 of file mTouch.c.