Functions

mTouch Filtering and Decoding Module

Functions

void CVD_Decode (void)
 Updates the state of the sensor using the current CVDSensorData value.
void CVD_Filter_UpdateAverage (unsigned int reading, unsigned char index)
 Updates the average for the given sensor.

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.


unsigned char ButtonState [CVD_NUMBER_SENSORS]
 Tracks the current state of each sensor.
unsigned int Average [CVD_NUMBER_SENSORS]
 Tracks environmental changes in the system.

Local Variables

These variables are used internally by the filtering and decoding framework modules. They should never be accessed outside of the mTouchCVD.c file.


unsigned int AverageCount [CVD_NUMBER_SENSORS]
 Counter variable for updating averages.
unsigned char PressTimer [CVD_NUMBER_SENSORS]
 Counter variable for button timeout implementation.
unsigned char DebounceCount [CVD_NUMBER_SENSORS]
 Counter variable for state transition debouncing.
unsigned int initCounter
 Counter variable for initialization.

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 unsigned int pressThreshold [] = PRESS_THRESHOLD_INIT
 Constant array containing the press thresholds.
const unsigned int releaseThreshold [] = RELEASE_THRESHOLD_INIT
 Constant array containing the release thresholds.

Detailed Description

The mTouch Filtering and Decoding module executes the detection algorithms for the framework. Using the latched output from the acquisition module, the service function is called each time a new value is available for each sensor. It will then loop through all of the active sensors and determine if they have changed state.

This is achieved by implementing a baseline average of the sensor's reading. The average is only updated while the sensor is in the CVD_RELEASED state. The difference between the average and the current reading is compared against the THRESHOLD_PRESS_SENSOR0 (or equivalent) value to determine if a change in state is necessary.

If the system sees that the reading has dipped below the average - the opposite direction of a finger press - the average will update itself based on the behavior chosen by configuration option NEGATIVE_CAPACITANCE.


Function Documentation

void CVD_Decode ( void   )

Updates the state of the sensor using the current CVDSensorData value.

This is the service routine that performs the functions of the decoding stage and should only be called once the mTouchCVD_dataReady variable has been set to a non-0 value.

Algorithm Implementation Notes

This function loops through each sensor and performs the following algorithm:

1. Get the current shift amount by comparing the new reading with the average and store it in the variable 'delta'. If delta is negative, clear the result by forcing it to '0'.

2. Based on the sensor's current state, perform one of the following procedures:

Initialization State

This is the default state of all sensors on power up. Once sensors leave the initialization state, they do not return. In this state, it begins by decrementing the initCounter variable. If initCounter has not yet reached 0, the average is updated to equal the current reading and a flag is set to stop any communication data from being transmitted. If initCounter has reached 0: the sensor transitions to the CVD_RELEASED state, the debounce counter is reset to 0, and the average is updated one final time to be equal to the current reading's value.

Released State

This state can be entered from either the CVD_INITIALIZING or CVD_PRESSED state. The only way to leave this state is by creating enough consecutive positive shifts to overflow the DebounceCount[i] variable. 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 average by at least the press threshold. If it is, it performs the debouncing logic. Once the debounce count has been reached, the sensor will change to the CVD_PRESSED state, reset the debounce counter, and initialize the press timer (if enabled).
If the threshold has not been crossed, the debounce counter is reset and the average is updated.

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

Pressed State

A sensor can only enter this state from the CVD_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 updating and checking the press timer counter variable. If it has reached 0, the sensor transfers to the CVD_RELEASED state, the debounce counter is reset and the average is re-initialized to the current reading. This is done to allow for a quick recovery if some environmental condition caused the sensor to become stuck.
Next, the reading is checked against the release threshold. If it has crossed the threshold, the debouncing and then a state transition to CVD_RELEASED is performed. If it has not crossed the threshold, the debounce counter is reset.

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

3. Now that all state machine decoding is complete, transmit fresh data information.




Definition at line 218 of file mTouchCVD.c.

Here is the call graph for this function:

void CVD_Filter_UpdateAverage ( unsigned int  reading,
unsigned char  index 
)

Updates the average for the given sensor.

Parameters:
[in]readingThe current reading value of the sensor
[in]indexThe index of the sensor to update

Updates a sensor's average (or baseline) in order to track the environmental changes of the system.

Algorithm Implementation Notes

This function has several possible implementations based on the current configuration options of the framework. The important configuration options are:

  • NEGATIVE_CAPACITANCE - determines how the average handles a negative reading shift
  • AVG_RATE - acts as a debounce counter for updating only every other scan, etc
  • AVG_UPDATE - determines what weight to give the reading when updating the average

The implementation begins by checking if NEGATIVE_CAPACITANCE is set to 1. If so, the average counter variable is set so that the average will perform its update regardless of the previous count. If NEGATIVE_CAPACITANCE is instead equal to 2, the average is immediately updated to follow the reading and the function is exited.
Next, the average updates the counter variable and compares it with AVG_RATE to see if it should continue or return. If the counter allows it to continue, the average is then updated using one of four possible implementations which is deteremined by the AVG_UPDATE option.




Definition at line 427 of file mTouchCVD.c.

Here is the caller graph for this function:


Variable Documentation

unsigned int Average[CVD_NUMBER_SENSORS]

Tracks environmental changes in the system.

GLOBAL: Tracks environmental changes in the system.

Definition at line 79 of file mTouchCVD.c.

unsigned int AverageCount[CVD_NUMBER_SENSORS]

Counter variable for updating averages.

Definition at line 90 of file mTouchCVD.c.

unsigned char ButtonState[CVD_NUMBER_SENSORS]

Tracks the current state of each sensor.

GLOBAL: Tracks the current state of the sensor.

Definition at line 78 of file mTouchCVD.c.

unsigned char DebounceCount[CVD_NUMBER_SENSORS]

Counter variable for state transition debouncing.

Definition at line 99 of file mTouchCVD.c.

unsigned int initCounter

Counter variable for initialization.

Definition at line 100 of file mTouchCVD.c.

const unsigned int pressThreshold[] = PRESS_THRESHOLD_INIT

Constant array containing the press thresholds.

Definition at line 112 of file mTouchCVD.c.

unsigned char PressTimer[CVD_NUMBER_SENSORS]

Counter variable for button timeout implementation.

Definition at line 95 of file mTouchCVD.c.

const unsigned int releaseThreshold[] = RELEASE_THRESHOLD_INIT

Constant array containing the release thresholds.

Definition at line 113 of file mTouchCVD.c.