Custom Hardware Quick Start Guide

Note:
This guide assumes you are using custom hardware. For details on where to begin when implementing the mTouch framework on the mTouch CVD Evaluation Kit, use this guide.

System Configuration

The mTouchCVD_Init() function will automatically configure the ADC, communications module (if enabled), and all required interrupts. There are only a few things the user is required to define on power-up:

  1. Configure the oscillator to provide a fast clock speed.
     OSCCON = 0b01110000;       // 32 MHz Fosc w/ PLLEN_ON config word on PIC16F1937
    

  2. Set the TMR0 prescaler. Weak pull-up resistors should be disabled.
    For more information about the implications of this setting, see Supported PIC® MCUs and Requirements.
     OPTION_REG = 0b10000000;   // TMR0 Prescaler = 1:2 (~40% processor usage)
    

  3. Sensor pins should be initialized as digital output low.
     ANSELA = 0b00000000;       // Digital
     TRISA  = 0b00000000;       // Output
     PORTA  = 0b00000000;       // Low   
    


Framework Configuration

Open mTouchCVD_Config.h and make the following edits:

  1. Set the _XTAL_FREQ value with the PIC® Microcontroller's Fosc speed in Hz
     #define _XTAL_FREQ         32000000
    

  2. Set the TMR0_PRESCALER value to the chosen TMR0 prescaler
     #define TMR0_PRESCALER     2
    

  3. Set the CVD_NUMBER_SENSORS value to the number of capacitive sensors in your design
     #define CVD_NUMBER_SENSORS 5
    

  4. Assign an analog channel to each sensor using the CVD_SENSOR0 definitions.
     #define CVD_SENSOR0        AN0 
     #define CVD_SENSOR1        AN1    
     #define CVD_SENSOR2        AN2    
     #define CVD_SENSOR3        AN3     
     #define CVD_SENSOR4        AN4   
    
    (Extra definitions - such as CVD_SENSOR5, in this case - will simply be ignored.)


Application Main Loop API Hooks

In your application's main loop:

  1. Use the mTouchCVD_isDataReady() function to determine when to service new mTouch readings.
  2. Once it's set, call mTouchCVD_Service(). The mTouchCVD_dataReady state is reset automatically.
     while(1)
     {
       if (mTouchCVD_isDataReady())   // Is new information ready?
       {
          mTouchCVD_Service();        // Decode the newly captured data and transmit new data updates.
       }
     }
    

  3. Use CVD_GetButtonState(i) to perform actions based on the sensor's state. (See also: CVD_ButtonState)
     #define LED0      LATA0
    
     #define LED_ON    0
     #define LED_OFF   1
    
     if (CVD_GetButtonState(0) < CVD_PRESSED)
     { 
       LED0 = LED_OFF;                // Sensor is either initializing or released.
     } else { 
       LED0 = LED_ON;                 // Sensor is pressed.
     } 
    

Your application should now compile and function. If you have enabled communications, you can see the real-time sensor readings using the mTouch CVD Framework GUI. For more information about adjusting the thresholds on sensors and further customizations, refer to the other Getting Started guides.