Defines | Functions

mTouch Acquisition Module

Generates and executes a configured version of the CVD acquisition routine. More...

Defines

#define GENERATE_JUMP_TABLE()
 Generates a jump table in ASM used by the acquisition ISR. Do not use directly.
#define GENERATE_STORAGE_FUNCTION()
 Generates the storage macro calls for the acquisition ISR. Do not use directly.
#define GENERATE_JUMP_TABLE()
 Generates a jump table in ASM used by the acquisition ISR. Do not use directly.
#define GENERATE_STORAGE_FUNCTION()
 Generates the storage macro calls for the acquisition ISR. Do not use directly.

Functions

void interrupt ISR (void)
 mTouch CVD Framework Interrupt Service Routine

mTouch Acquisition ISR Variables

These variables are used by the ISR of the mTouch Framework and should not be directly accessed by the main loop application.


unsigned short long CVD_Acq_Filtered_Data [CVD_NUMBER_SENSORS]
 Accumulator array for sensor oversampling.
bank0 unsigned int last_result
 Stores ADC results for differential calculation.
bank0 unsigned int sample_counter = CVD_SAMPLES_PER_SCAN
 Counter variable for oversampling.
unsigned int sensor_data [CVD_NUMBER_SENSORS]
 Decimate-filtered differential ADC result register.
unsigned int CVDSensorData [CVD_NUMBER_SENSORS]
 Latch register storing the latest acquisition data.
unsigned char mTouchCVD_jitter = 0x55
 Stores the current random seed value for jittering.
bank0 unsigned char current_sensor
 Currently scanned sensor index value.
unsigned char mTouchCVD_dataReady
 GLOBAL: Flag to determine if new data is ready for processing.

Housekeeping Macros

These macros perform basic ISR and timer module functions such as checking that the interrupt flag is set and reloading the TMR0 counter.


#define CHECK_AND_CLEAR_TMR0IF()
 Checks the TMR0IF and determines whether the mTouch ISR is executed.
#define JITTER_START_TIME()
 Calculates a random value and uses it to seed TMR0.
#define WAIT_FOR_GODONE_BIT()   while (GO_nDONE);
 Implements a while loop waiting on the GO/DONE bit to be cleared.
#define STORE_LAST_RESULT()
 Stores the ADC result into the last_result variable.

Timing Critical CVD Scanning Routine Macros

These macros implement the CVD scanning routine and basic acquistion-level filtering techniques. Editting these macros could reduce the noise immunity of the system.


#define READ_SENSOR(indexSensor, indexRef)   READ_SENSOR_EXPANDED(__paste(CVD_SELECT_SENSOR,indexSensor),__paste(CVD_SELECT_SENSOR,indexRef),__paste(CVD_PORT_SENSOR,indexSensor),__paste(CVD_PIN_SENSOR,indexSensor),__paste(CVD_PORT_SENSOR,indexRef),__paste(CVD_PIN_SENSOR,indexRef))
 Perform a differential CVD scan on the sensor.
#define READ_SENSOR_EXPANDED(current_channel, ref_channel, port, pin, ref_port, ref_pin)
 Expanded utility macro called by READ_SENSOR(). Do not use directly.
#define CVD_DECIMATE()
 Generates ASM code to compare the previous sensor's scan result with its slew rate limited latch register, sensor_data.
#define CVD_SENSOR_SMALLER()
 Generates ASM code to decrement the slew rate limited sensor_data latch register.
#define CVD_DECIMATE_END()
 Generates ASM code to decrement the slew rate limited sensor_data latch register.

Polishing/Finishing Macros

These macros perform scaling and final operations before setting the mTouchCVD_dataReady flag and allowing the main loop application to process the new data.


#define STORE_SENSOR(index)   STORE_SENSOR_SCALE(index, 4)
 Scales the accumulated result of the CVD acquisition and stores it for main-application access.
#define EXIT_SENSOR(index)
 Increments the given index variable and exits the ISR.
#define EXIT_LAST_SENSOR(index)   EXIT_LAST_SENSOR_MAIN()
 Performs several important functions after all sensors have been scanned.
#define SET_DATA_READY_FLAG()
 Sets the dataReady flag to signal the main application of a new reading.

Housekeeping Macros

These macros perform basic ISR and timer module functions such as checking that the interrupt flag is set and reloading the TMR0 counter.


#define SAVE_STATE()
 Executes any required actions to save the current main-loop process.
#define RESTORE_STATE()
 Executes any required actions to save the current main-loop process.
#define CHECK_AND_CLEAR_TMR0IF()
 Checks the TMR0IF and determines whether the mTouch ISR is executed.
#define JITTER_START_TIME()
 Calculates a random value and uses it to seed TMR0.
#define WAIT_FOR_GODONE_BIT()   while (GO_nDONE);
 Implements a while loop waiting on the GO/DONE bit to be cleared.
#define STORE_LAST_RESULT()
 Stores the ADC result into the last_result variable.

Timing Critical CVD Scanning Routine Macros

These macros implement the CVD scanning routine and basic acquistion-level filtering techniques. Editting these macros could reduce the noise immunity of the system.


#define READ_SENSOR(indexSensor, indexRef)   READ_SENSOR_EXPANDED(__paste(CVD_SELECT_SENSOR,indexSensor),__paste(CVD_SELECT_SENSOR,indexRef),__paste(CVD_PORT_SENSOR,indexSensor),__paste(CVD_PIN_SENSOR,indexSensor),__paste(CVD_PORT_SENSOR,indexRef),__paste(CVD_PIN_SENSOR,indexRef))
 Perform a differential CVD scan on the sensor.
#define READ_SENSOR_EXPANDED(current_channel, ref_channel, port, pin, ref_port, ref_pin)
 Expanded utility macro called by READ_SENSOR(). Do not use directly.
#define CVD_DECIMATE()
 Generates ASM code to compare the previous sensor's scan result with its decimate-filtered latch register, sensor_data.
#define CVD_SENSOR_SMALLER()
 Generates ASM code to decrement the decimate-filtered sensor_data latch register.
#define CVD_DECIMATE_END()
 Generates ASM code to decrement the decimate-filtered sensor_data latch register.

Polishing/Finishing Macros

These macros perform scaling and final operations before setting the mTouchCVD_dataReady flag and allowing the main loop application to process the new data.


#define STORE_SENSOR(index)   STORE_SENSOR_SCALE(index, 4)
 Scales the accumulated result of the CVD acquisition and stores it for main-application access.
#define EXIT_SENSOR(index)
 Increments the given index variable and exits the ISR.
#define EXIT_LAST_SENSOR(index)   EXIT_LAST_SENSOR_MAIN()
 Performs several important functions after all sensors have been scanned.
#define SET_DATA_READY_FLAG()
 Sets the dataReady flag to signal the main application of a new reading.

Detailed Description

Generates and executes a configured version of the CVD acquisition routine.

The mTouch Acquisition module generates an assembly implementation of the interrupt service routine that is designed to maximize noise immunity and minimize execution time. It will automatically add and remove macros as the number of sensors in the application changes. By default, it will use the previously scanned sensor as the reference for the current scan. If the application only has a single sensor, a special acquisition method which does not require a reference sensor is used. This specialized method should not be used in systems with more than one sensor due to crosstalk concerns.


Define Documentation

#define CHECK_AND_CLEAR_TMR0IF (  )
Value:
do {                                                                                        \
    if (TMR0IF == 0)                                                                        \
    {                              /* T0IF is not set so,                               */  \
        asm("ljmp END_ISR");       /* exit the mTouch ISR                               */  \
    } else {                       /* T0IF is set, so                                   */  \
        TMR0IF = 0;                /* clear it and continue with mTouch ISR service     */  \
    }                                                                                       \
} while (0)

Checks the TMR0IF and determines whether the mTouch ISR is executed.

Parameters:
[in]None

Definition at line 126 of file mTouchCVD_macroLibrary_PIC16F.h.

#define CHECK_AND_CLEAR_TMR0IF (  )
Value:
do {                                                                                        \
    if (TMR0IF == 0)                                                                        \
    {                              /* T0IF is not set so,                               */  \
        asm("ljmp END_ISR");       /* exit the mTouch ISR                               */  \
    } else {                       /* T0IF is set, so                                   */  \
        TMR0IF = 0;                /* clear it and continue with mTouch ISR service     */  \
    }                                                                                       \
} while (0)

Checks the TMR0IF and determines whether the mTouch ISR is executed.

Parameters:
[in]None

Definition at line 116 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define CVD_DECIMATE (  )
Value:
do {                                                    \
            if (last_result > sensor_data[0]) {                 \
                sensor_data[0]++;                               \
            } else {                                            \
                sensor_data[0]--;                               \
            }                                                   \
            CVD_Acq_Filtered_Data[0] += sensor_data[0];         \
            WAIT_FOR_GODONE_BIT();                              \
            last_result = (unsigned int)(ADRESH << 8) + ADRESL; \
            asm("return");                                      \
        } while(0)

Generates ASM code to compare the previous sensor's scan result with its slew rate limited latch register, sensor_data.

Parameters:
[in]None

Definition at line 496 of file mTouchCVD_macroLibrary_PIC16F.h.

#define CVD_DECIMATE (  )
Value:
do {                                                                \
    asm("BANKSEL    _last_result");                                 \
    asm("movlw LOW  _sensor_data");                                 \
    asm("movwf      _FSR0L");                                       \
    asm("movlw HIGH _sensor_data");                                 \
    asm("movwf      _FSR0H");                                       \
    asm("movf       _INDF0,W");                                     \
    asm("subwf      _last_result,F");                               \
    asm("incf       _FSR0L,F");                                     \
    asm("movf       _INDF0,W");                                     \
    asm("subwfb     _last_result+1,W");                             \
    asm("decf       _FSR0L,F");                                     \
    asm("btfss      _STATUS,0");                                    \
    asm("ljmp       sensor_smaller");                               \
    asm("iorwf      _last_result,W");                               \
    asm("btfss      _STATUS,2");                                    \
    asm("movlw      1");                                            \
    asm("addwf      _INDF0,F");                                     \
    asm("movf       _INDF0,W");                                     \
    asm("movwf      _last_result,F");                               \
    asm("incf       _FSR0L,F");                                     \
    asm("btfsc      _STATUS,0");                                    \
    asm("incf       _INDF0,F");                                     \
    asm("movf       _INDF0,W");                                     \
    asm("movwf      _last_result+1");                               \
    asm("ljmp       decimate_end");                                 \
} while (0)

Generates ASM code to compare the previous sensor's scan result with its decimate-filtered latch register, sensor_data.

Parameters:
[in]None

Definition at line 527 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define CVD_DECIMATE_END (  )

Generates ASM code to decrement the slew rate limited sensor_data latch register.

Parameters:
[in]None

Definition at line 509 of file mTouchCVD_macroLibrary_PIC16F.h.

#define CVD_DECIMATE_END (  )
Value:
do {                                                                \
    asm("movlw LOW  _CVD_Acq_Filtered_Data");                       \
    asm("movwf      _FSR0L");                                       \
    asm("movlw HIGH _CVD_Acq_Filtered_Data");                       \
    asm("movwf      _FSR0H");                                       \
    asm("movf       _last_result,W");                               \
    asm("addwf      _INDF0,F");                                     \
    asm("incf       _FSR0L,F");                                     \
    asm("movf       _last_result+1,W");                             \
    asm("addwfc     _INDF0,F");                                     \
    asm("incf       _FSR0L,F");                                     \
    asm("btfsc      _STATUS,0");                                    \
    asm("incf       _INDF0,F");                                     \
    asm("BANKSEL    _ADCON0");                                      \
    asm("btfsc    " ___mkstr(MASKBANK(_ADCON0,1)) ",1");            \
    asm("goto       $-1");                                          \
    asm("movf     " ___mkstr(MASKBANK(_ADRESH,1)) ",W");            \
    asm("BANKSEL    _last_result");                                 \
    asm("movwf    " ___mkstr(MASKBANK(_last_result+1,0)));          \
    asm("BANKSEL    _ADRESL");                                      \
    asm("movf     " ___mkstr(MASKBANK(_ADRESL,1)) ",W");            \
    asm("BANKSEL    _last_result");                                 \
    asm("movwf    " ___mkstr(MASKBANK(_last_result,0)));            \
    asm("return");                                                  \
} while(0)

Generates ASM code to decrement the decimate-filtered sensor_data latch register.

Parameters:
[in]None

Definition at line 569 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define CVD_SENSOR_SMALLER (  )

Generates ASM code to decrement the slew rate limited sensor_data latch register.

Parameters:
[in]None

Definition at line 508 of file mTouchCVD_macroLibrary_PIC16F.h.

#define CVD_SENSOR_SMALLER (  )
Value:
do {                                                                \
    asm("movlw      1");                                            \
    asm("subwf      _INDF0,F");                                     \
    asm("movf       _INDF0,W");                                     \
    asm("movwf      _last_result");                                 \
    asm("incf       _FSR0L,F");                                     \
    asm("btfss      _STATUS,0");                                    \
    asm("decf       _INDF0,F");                                     \
    asm("movf       _INDF0,W");                                     \
    asm("movwf      _last_result+1");                               \
} while (0)

Generates ASM code to decrement the decimate-filtered sensor_data latch register.

Parameters:
[in]None

Definition at line 556 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define EXIT_LAST_SENSOR (   index )    EXIT_LAST_SENSOR_MAIN()

Performs several important functions after all sensors have been scanned.

Resets the index variable to 0 for the next scan, decrements the oversampling counter to determine if it is time to complete the sample and store the result, and then exits the ISR.

Parameters:
[in]indexthe index variable to reset to 0

Definition at line 631 of file mTouchCVD_macroLibrary_PIC16F.h.

#define EXIT_LAST_SENSOR (   index )    EXIT_LAST_SENSOR_MAIN()

Performs several important functions after all sensors have been scanned.

Resets the index variable to 0 for the next scan, decrements the oversampling counter to determine if it is time to complete the sample and store the result, and then exits the ISR.

Parameters:
[in]indexthe index variable to reset to 0

Definition at line 716 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define EXIT_SENSOR (   index )
Value:
do {                                                                                                \
    index++;                                                                                        \
    asm("ljmp END_ISR");                            /* Exit the ISR                             */  \
} while(0)

Increments the given index variable and exits the ISR.

Parameters:
[in]indexthe index variable to increment

Definition at line 599 of file mTouchCVD_macroLibrary_PIC16F.h.

#define EXIT_SENSOR (   index )
Value:
do {                                                                                                \
    index++;                                                                                        \
    asm("ljmp END_ISR");                            /* Exit the ISR                             */  \
} while(0)

Increments the given index variable and exits the ISR.

Parameters:
[in]indexthe index variable to increment

Definition at line 684 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define GENERATE_JUMP_TABLE (  )

Generates a jump table in ASM used by the acquisition ISR. Do not use directly.

Parameters:
[in]None

Definition at line 926 of file mTouchCVD_macroLibrary_PIC16F.h.

#define GENERATE_JUMP_TABLE (  )

Generates a jump table in ASM used by the acquisition ISR. Do not use directly.

Parameters:
[in]None

Definition at line 1009 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define GENERATE_STORAGE_FUNCTION (  )

Generates the storage macro calls for the acquisition ISR. Do not use directly.

Parameters:
[in]None

Definition at line 1078 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define GENERATE_STORAGE_FUNCTION (  )

Generates the storage macro calls for the acquisition ISR. Do not use directly.

Parameters:
[in]None

Definition at line 995 of file mTouchCVD_macroLibrary_PIC16F.h.

#define JITTER_START_TIME (  )
Value:
do {                                                                        \
            asm("BANKSEL    _TMR0");    /* Move to Bank 0 to access TMR0 SFR    */  \
            asm("clrf       _TMR0");    /* Clear TMR0                           */  \
        } while (0)

Calculates a random value and uses it to seed TMR0.

The implementation is based on the CVD_JITTER_TYPE configuration option.

If CVD_JITTER_TYPE == 0, the LSb's of the ADRESL register will be used to seed TMR0 with a starting value.

If CVD_JITTER_TYPE == 1, a linear feedback shift register algorithm will be implemented to increase the randomness of the jitter function. This implementation costs an extra byte of ram and a slightly longer execution time.

Parameters:
[in]None

Definition at line 178 of file mTouchCVD_macroLibrary_PIC16F.h.

#define JITTER_START_TIME (  )
Value:
do {                                                                        \
            asm("movlb      0"      );  /* Move to Bank 0 to access TMR0 SFR    */  \
            asm("clrf       _TMR0"  );  /* Clear TMR0                           */  \
        } while (0)

Calculates a random value and uses it to seed TMR0.

The implementation is based on the CVD_JITTER_TYPE configuration option.

If CVD_JITTER_TYPE == 0, the LSb's of the ADRESL register will be used to seed TMR0 with a starting value.

If CVD_JITTER_TYPE == 1, a linear feedback shift register algorithm will be implemented to increase the randomness of the jitter function. This implementation costs an extra byte of ram and a slightly longer execution time.

Parameters:
[in]None

Definition at line 168 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define READ_SENSOR (   indexSensor,
  indexRef 
)    READ_SENSOR_EXPANDED(__paste(CVD_SELECT_SENSOR,indexSensor),__paste(CVD_SELECT_SENSOR,indexRef),__paste(CVD_PORT_SENSOR,indexSensor),__paste(CVD_PIN_SENSOR,indexSensor),__paste(CVD_PORT_SENSOR,indexRef),__paste(CVD_PIN_SENSOR,indexRef))

Perform a differential CVD scan on the sensor.

This macro is used to abstract the READ_SENSOR_EXPANDED() macro. This allows us to use 6 arguments in the actual macro implementation, but only 2 are required in the mTouchCVD_Acquisition.c macro call.

This macro will provide the correct ADCON0, Port, and Pin values for the READ_SENSOR_EXPANDED() macro based on the given sensor index.

Parameters:
[in]indexSensorthe index of the sensor to be scanned
[in]indexRefthe index of the sensor to be used as the reference

Definition at line 232 of file mTouchCVD_macroLibrary_PIC16F.h.

#define READ_SENSOR (   indexSensor,
  indexRef 
)    READ_SENSOR_EXPANDED(__paste(CVD_SELECT_SENSOR,indexSensor),__paste(CVD_SELECT_SENSOR,indexRef),__paste(CVD_PORT_SENSOR,indexSensor),__paste(CVD_PIN_SENSOR,indexSensor),__paste(CVD_PORT_SENSOR,indexRef),__paste(CVD_PIN_SENSOR,indexRef))

Perform a differential CVD scan on the sensor.

This macro is used to abstract the READ_SENSOR_EXPANDED() macro. This allows us to use 6 arguments in the actual macro implementation, but only 2 are required in the mTouchCVD_Acquisition.c macro call.

This macro will provide the correct ADCON0, Port, and Pin values for the READ_SENSOR_EXPANDED() macro based on the given sensor index.

Parameters:
[in]indexSensorthe index of the sensor to be scanned
[in]indexRefthe index of the sensor to be used as the reference

Definition at line 222 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define READ_SENSOR_EXPANDED (   current_channel,
  ref_channel,
  port,
  pin,
  ref_port,
  ref_pin 
)

Expanded utility macro called by READ_SENSOR(). Do not use directly.

This is the full implementation routine for the CVD acquisition. The algorithm steps will changed based on the processor core being used, but the general steps should remain the same:

Reference-Sensor CVD Scanning Algorithm Steps:

1. Scan A - Sensor High, Reference Low

  • To begin, ADCON0 is set so that the mux will point to the reference sensor. The reference sensor is already output low.
  • The reference sensor is then set low (just in case) and the sensor to be scanned is set high.
  • The new ADCON0 value which will point to the scanning sensor is loaded into the working register and a short delay is implemented to allow the internal hold capacitor enough time to discharge.
  • The sensor's port is set as an input and ADCON0 is immediately loaded with the new mux value.
  • After a short delay to allow the charges to settle, the Go/Done bit is set to begin the ADC conversion. The sensor port is then set back to an output to minimize noise.

2. Execute Math while ADC Performs Conversion

  • The CVD_DECIMATE(), CVD_SENSOR_SMALLER(), and CVD_DECIMATE_END() macros are now used to perform calculations based on the previous ISR's results. The result of Scan A is also stored into the last_result variable to later have Scan B's result subtracted from it.

3. Scan B - Sensor Low, Reference High
The exact process as Scan A is repeated, but with the voltage levels of the sensor and the reference reversed.

  • ADCON0 mux is set to the reference sensor.
  • Reference sensor is set to output high, sensor is output low.
  • After a short delay, sensor is set to an input.
  • ADCON0 mux is set to the sensor.
  • After a short settling delay, the Go/Done bit is set.
  • Sensor is set to an output.

4. The ISR then exits and stores the ADC result at the start of the next ISR.

Single-Sensor CVD Scanning Algorithm Steps:

Since we are now going to be using the same sensor to charge the internal ADC capacitor and perform our scan, the steps are going to change slightly. The overall, algorithmic process is the same as above, however. First we scan with the internal hold capacitor as a high reference, then we perform math on the previous ISR's result, and then we scan in the opposite direction - internal hold capacitor is low, sensor is high.

  • Sensor is output low to begin
  • ADCON0 is set to point to the sensor and the Go/Done bit is set. This provides a very small window that allows the internal hold capacitor to gain some charge from the external sensor. Since the Go/Done bit is set at the same time, the internal hold capacitor will be disconnected from the sensor.
  • The ADCON0 register is then set to point to an isolated, unimplemented ADC channel option and the Go/Done bit is cleared. This stops the conversion that just begin and isolates the now-charged hold capacitor from the sensor.
  • The sensor is then set output low to remove all charge.
  • The sensor is set to an input and ADCON0 is set to point to the sensor.
  • After some settling time, the ADCON0 register then points to an isolated sensor option and begins the conversion.
Parameters:
[in]current_channelthe ADCON0 value that points to the sensor to be scanned
[in]ref_channelthe ADCON0 value that points to the sensor to be used as a reference
[in]portthe sensor's port register
[in]pinthe sensor's pin assignment
[in]ref_portthe reference's port register
[in]ref_pinthe reference's pin assignment

Definition at line 366 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define READ_SENSOR_EXPANDED (   current_channel,
  ref_channel,
  port,
  pin,
  ref_port,
  ref_pin 
)

Expanded utility macro called by READ_SENSOR(). Do not use directly.

This is the full implementation routine for the CVD acquisition. The algorithm steps will changed based on the processor core being used, but the general steps should remain the same:

Reference-Sensor CVD Scanning Algorithm Steps:

1. Scan A - Sensor High, Reference Low

  • To begin, ADCON0 is set so that the mux will point to the reference sensor. The reference sensor is already output low.
  • The reference sensor is then set low (just in case) and the sensor to be scanned is set high.
  • The new ADCON0 value which will point to the scanning sensor is loaded into the working register and a short delay is implemented to allow the internal hold capacitor enough time to discharge.
  • The sensor's port is set as an input and ADCON0 is immediately loaded with the new mux value.
  • After a short delay to allow the charges to settle, the Go/Done bit is set to begin the ADC conversion. The sensor port is then set back to an output to minimize noise.

2. Execute Math while ADC Performs Conversion

  • The CVD_DECIMATE(), CVD_SENSOR_SMALLER(), and CVD_DECIMATE_END() macros are now used to perform calculations based on the previous ISR's results. The result of Scan A is also stored into the last_result variable to later have Scan B's result subtracted from it.

3. Scan B - Sensor Low, Reference High
The exact process as Scan A is repeated, but with the voltage levels of the sensor and the reference reversed.

  • ADCON0 mux is set to the reference sensor.
  • Reference sensor is set to output high, sensor is output low.
  • After a short delay, sensor is set to an input.
  • ADCON0 mux is set to the sensor.
  • After a short settling delay, the Go/Done bit is set.
  • Sensor is set to an output.

4. The ISR then exits and stores the ADC result at the start of the next ISR.

Single-Sensor CVD Scanning Algorithm Steps:

Since we are now going to be using the same sensor to charge the internal ADC capacitor and perform our scan, the steps are going to change slightly. The overall, algorithmic process is the same as above, however. First we scan with the internal hold capacitor as a high reference, then we perform math on the previous ISR's result, and then we scan in the opposite direction - internal hold capacitor is low, sensor is high.

  • Sensor is output low to begin
  • ADCON0 is set to point to the sensor and the Go/Done bit is set. This provides a very small window that allows the internal hold capacitor to gain some charge from the external sensor. Since the Go/Done bit is set at the same time, the internal hold capacitor will be disconnected from the sensor.
  • The ADCON0 register is then set to point to an isolated, unimplemented ADC channel option and the Go/Done bit is cleared. This stops the conversion that just begin and isolates the now-charged hold capacitor from the sensor.
  • The sensor is then set output low to remove all charge.
  • The sensor is set to an input and ADCON0 is set to point to the sensor.
  • After some settling time, the ADCON0 register then points to an isolated sensor option and begins the conversion.
Parameters:
[in]current_channelthe ADCON0 value that points to the sensor to be scanned
[in]ref_channelthe ADCON0 value that points to the sensor to be used as a reference
[in]portthe sensor's port register
[in]pinthe sensor's pin assignment
[in]ref_portthe reference's port register
[in]ref_pinthe reference's pin assignment

Definition at line 358 of file mTouchCVD_macroLibrary_PIC16F.h.

#define RESTORE_STATE (  )
Value:
do {                                            \
} while (0)

Executes any required actions to save the current main-loop process.

Parameters:
[in]None

Definition at line 102 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define SAVE_STATE (  )
Value:
do {                                            \
} while (0)

Executes any required actions to save the current main-loop process.

Parameters:
[in]None

Definition at line 88 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define SET_DATA_READY_FLAG (  )
Value:
do {                                                                \
    mTouchCVD_dataReady = 1;                                        \
} while(0)

Sets the dataReady flag to signal the main application of a new reading.

Parameters:
[in]None

Definition at line 652 of file mTouchCVD_macroLibrary_PIC16F.h.

#define SET_DATA_READY_FLAG (  )
Value:
do {                            \
        mTouchCVD_dataReady = 1;    \
    } while(0)

Sets the dataReady flag to signal the main application of a new reading.

Parameters:
[in]None

Definition at line 736 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define STORE_LAST_RESULT (  )
Value:
do {                                                                            \
    last_result = (unsigned int)((ADRESH | 0x04) << 8) + ADRESL - last_result;  \
} while (0)

Stores the ADC result into the last_result variable.

This macro is called near the beginning of the mTouch ISR to store the previous ADC scan's result. Since this result is from Scan B of the READ_SENSOR_EXPANDED() macro, we subtract the ADRES value from the current last_result value which stores the result from Scan A.

Parameters:
[in]None

Definition at line 205 of file mTouchCVD_macroLibrary_PIC16F.h.

#define STORE_LAST_RESULT (  )
Value:
do {                                                                            \
    last_result = (unsigned int)((ADRESH | 0x04) << 8) + ADRESL - last_result;  \
} while (0)

Stores the ADC result into the last_result variable.

This macro is called near the beginning of the mTouch ISR to store the previous ADC scan's result. Since this result is from Scan B of the READ_SENSOR_EXPANDED() macro, we subtract the ADRES value from the current last_result value which stores the result from Scan A.

Parameters:
[in]None

Definition at line 195 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define STORE_SENSOR (   index )    STORE_SENSOR_SCALE(index, 4)

Scales the accumulated result of the CVD acquisition and stores it for main-application access.

This macro uses the CVD_SCALING configuration option to determine which scaling option to choose.

Parameters:
[in]indexthe index of the sensor to be scaled and stored

Definition at line 674 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define STORE_SENSOR (   index )    STORE_SENSOR_SCALE(index, 4)

Scales the accumulated result of the CVD acquisition and stores it for main-application access.

This macro uses the CVD_SCALING configuration option to determine which scaling option to choose.

Parameters:
[in]indexthe index of the sensor to be scaled and stored

Definition at line 589 of file mTouchCVD_macroLibrary_PIC16F.h.

#define WAIT_FOR_GODONE_BIT (  )    while (GO_nDONE);

Implements a while loop waiting on the GO/DONE bit to be cleared.

Parameters:
[in]None

Definition at line 181 of file mTouchCVD_macroLibrary_PIC16F1.h.

#define WAIT_FOR_GODONE_BIT (  )    while (GO_nDONE);

Implements a while loop waiting on the GO/DONE bit to be cleared.

Parameters:
[in]None

Definition at line 191 of file mTouchCVD_macroLibrary_PIC16F.h.


Function Documentation

void interrupt ISR ( void   )

mTouch CVD Framework Interrupt Service Routine

Implements the acquisition process for the mTouch CVD Framework. Adding code to the beginning of this function could significantly affect the noise performance of your final system. To avoid complications, add any necessary ISR functionality to the end of the ISR - after the mTouch scanning process is complete. Be careful that you are leaving enough time outside of the ISR to process the main line application.

Algorithm Implementation Notes

1. If required, save the current state of the main loop application.

2. Check and clear the TMR0IF flag. If it has not been set, jump to END_ISR.

3. Reload TMR0 with a jittered reload value to prepare for the next mTouch scan after this one.

4. Check that the Go/Done bit of the ADC has been cleared.

5. Store the result of the previous sensor's ADC scan by subtracting it from the value stored in last_result. This creates the 'differential' value that will be accumulated in the next step.

6. Implement and use a jump table based on which sensor should be scanned next.

6. Generate the correct macro functions to implement the mTouch CVD scanning algorithms. This step uses the number of sensors to implement a 'previous sensor used as the reference sensor' configuration. The last sensor uses the EXIT_LAST_SENSOR() macro instead of the EXIT_SENSOR() macro. This allows the storage function to be performed instead of immediately moving to the END_ISR label.

8. Uses the number of sensors to generate a storage macro for each sensor. This step is only reached after a decrementing counter, initialized to CVD_SAMPLES_PER_SCAN, reaches 0.

9. Sets the mTouchCVD_dataReady flag so the main application knows to process the new data.




10. Sets the mTouchCVD_dataReady flag so the main application knows to process the new data.

Adding Additional ISR Checks and Functionality

END_ISR is the place the mTouchCVD_ISR will jump to when its finished performing its service.

Add additional application ISR functions/checks above the RESTORE_STATE() macro. You may program in C.




Decimation Helper Function

The 'decimate' function is used in each of the READ_SENSOR() calls to perform some common math calculations on the previous sensor scan's result. It has been implemented as a macro to allow for different implementations based on the chosen PIC microcontroller's core.




Definition at line 117 of file mTouchCVD_Acquistion.c.


Variable Documentation

bank0 unsigned char current_sensor

Currently scanned sensor index value.

Definition at line 88 of file mTouchCVD_Acquistion.c.

unsigned short long CVD_Acq_Filtered_Data[CVD_NUMBER_SENSORS]

Accumulator array for sensor oversampling.

Definition at line 76 of file mTouchCVD_Acquistion.c.

unsigned int CVDSensorData[CVD_NUMBER_SENSORS]

Latch register storing the latest acquisition data.

GLOBAL: Latch register storing the latest acquisition data.

Definition at line 82 of file mTouchCVD_Acquistion.c.

bank0 unsigned int last_result

Stores ADC results for differential calculation.

Definition at line 77 of file mTouchCVD_Acquistion.c.

unsigned char mTouchCVD_dataReady

GLOBAL: Flag to determine if new data is ready for processing.

Flag to register new sensor values.

Example usage:

 while(1)
 {
   if (mTouchCVD_isDataReady())   // Is new information ready?
   {
      mTouchCVD_Service();        // Decode the newly captured data and transmit new data updates.
   }
 }

Definition at line 80 of file mTouchCVD_Acquistion.c.

unsigned char mTouchCVD_jitter = 0x55

Stores the current random seed value for jittering.

Definition at line 85 of file mTouchCVD_Acquistion.c.

bank0 unsigned int sample_counter = CVD_SAMPLES_PER_SCAN

Counter variable for oversampling.

Definition at line 78 of file mTouchCVD_Acquistion.c.

unsigned int sensor_data[CVD_NUMBER_SENSORS]

Decimate-filtered differential ADC result register.

GLOBAL: Internal mTouch acquisition variable - do not modify.

Definition at line 81 of file mTouchCVD_Acquistion.c.