This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR2675: Dynamic parameters for capacitive touch

Part Number: MSP430FR2675


Hi everyone,

I would like to know if it's possible to dynamicaly set the capacitive touch parameters of my MSP430, ie conversion count, proximity and touch thresholds. I tried to set parameters as noinit so I can change the value and keep it in persitent memory (a method I use for another parameter), but I've got an error "#28 expression must have a constant value".

I'm pretty sure it is possible to change those value while the MSP is running, as it's what we do when we use Captivate Design Center tool to calibrate the touch sensors.

Any help on this would be very appreciated.

Best regards,

Yoann

#include "CAPT_UserConfig.h"

#pragma NOINIT(conv_count)
uint16_t conv_count;
#pragma NOINIT(prox_threshold)
uint16_t prox_threshold;
#pragma NOINIT(touch_threshold)
uint16_t touch_threshold;

//*****************************************************************************
//
//! Captivate Element Definitions
//! All elements in this application are defined below.
//! Each element has 3 components:
//!  1) a raw count array (One index per freq. scanned) (uint16_t)
//!  2) a tuning array (One index per freq. scanned) (tCaptivateElementTuning)
//!  3) a element structure (tElement)
//
//*****************************************************************************

// Sensor: PRX01, Element: E00
uint16_t PRX01_E00_RawCnts[CAPT_SELF_FREQ_CNT];
tCaptivateElementTuning PRX01_E00_Tuning[CAPT_SELF_FREQ_CNT];
tElement PRX01_E00 =
{
    .ui8RxPin = 0,
    .ui8RxBlock = 1,
    .ui8TouchThreshold = touch_threshold,
    .pRawCount = PRX01_E00_RawCnts,
    .pTuning = PRX01_E00_Tuning,
};


//*****************************************************************************
//
//! Captivate Time Cycle Definitions
//! All time cycles in this application are defined below.  Time cycles are
//! groups of elements that are measured together in parallel in one time slot.
//! Each cycle has 2 components:
//!  1) an element pointer array to the member elements (tElement*)
//!  2) a cycle structure (tCycle)
//
//*****************************************************************************

// Time Cycle: PRX01_C00
tElement* PRX01_C00_Elements[1] =
{
    &PRX01_E00,
};
tCycle PRX01_C00 =
{
    .ui8NrOfElements = 1,
    .pElements = PRX01_C00_Elements,
};


//*****************************************************************************
//
//! Captivate Sensor Definitions
//! All sensors in this application are defined below.  Sensors are
//! groups of time cycles that utilize raw measurement data to create an
//! abstract sensor type, such as a button, slider, wheel, or prox sensor.
//! Each sensor has 3 components:
//!  1) a cycle pointer array to the member time cycles (tCycle*)
//!  2) a sensor-specific parameter structure (tGenericSensorParams)
//!  3) a sensor structure (tSensor)
//
//*****************************************************************************

//Sensor: PRX01
const tCycle* PRX01_Cycles[1] =
{
    &PRX01_C00,
};

tProxSensorParams PRX01_Params =
{
    .pSensor = NULL,
    .ui8NumberOfSensors = 0,
};

tSensor PRX01 =
{
    // Basic Properties
    .TypeOfSensor = eProx,
    .SensingMethod = eSelf,
    .DirectionOfInterest = eDOIDown,
    .pvCallback = NULL,
    .ui8NrOfCycles = 1,
    .pCycle = PRX01_Cycles,
    .pSensorParams = (tGenericSensorParams*)&PRX01_Params,
    // Conversion Control Parameters
    .ui16ConversionCount = conv_count,
    .ui16ConversionGain = 200,
    .ui8FreqDiv = 2,
    .ui8ChargeLength = 0,
    .ui8TransferLength = 0,
    .bModEnable = false,
    .ui8BiasControl = 3,
    .bCsDischarge = true,
    .bLpmControl = false,
    .ui8InputSyncControl = 0,
    .bTimerSyncControl = false,
    .bIdleState = true,
    // Tuning  Parameters
    .ui16ProxThreshold = prox_threshold,
    .ui16NegativeTouchThreshold = 30,
    .ui16ErrorThreshold = 8191,
    .ui16TimeoutThreshold = 65535,
    .ProxDbThreshold.DbIn = 1,
    .ProxDbThreshold.DbOut = 0,
    .TouchDbThreshold.DbIn = 1,
    .TouchDbThreshold.DbOut = 0,
    .bCountFilterEnable = true,
    .ui8CntBeta = 1,
    .bSensorHalt = false,
    .bPTSensorHalt = true,
    .bPTElementHalt = true,
    .ui8LTABeta = 7,
    .bReCalibrateEnable = true,
};

  • Hi Yoann,

    There are two methods; one is directly accessing the member in the sensor struct. The other is indirectly using a pointer.

    In the code examples I show both methods in a callback function.  Of course you can do this were you need to.

    /* Direct access
     * Must use extern in the file you wish to access the sensor struct 
     */
    extern tSensor keypadSensor;
    void Demo_keypadSensorHandler(tSensor* pSensor)
    {
        uint16_t conversionCount;
        
        /* Direct access */
        conversionCount = keypadSensor.ui16ConversionCount;
    }
    
    /* Indirect access */
    void Demo_keypadSensorHandler(tSensor* pSensor)
    {
        uint16_t conversionCount;
    
        /* Indirect access using pointer */
        conversionCount = pSensor->ui16ConversionCount;
    
    }
    

  • Hi Dennis,

    Thanks for your answer, but sorry I meant to dynamically set, not get the touch parameters.

    To tell you more about my application, we've got several products with the same PCB and because of their differences in terms of mechanics, the calibration are not the same, so are the touch parameters. I would like to have a common software on my products, and just give the parameters after flashing the code to the MSP.

    Let me know if I'm not clear.

    Yoann

  • Ok, then to set a sensor's conversion count or gain or thresholds, for example,  you simply reverse the assignment as follows and assign whatever value you need.

        pSensor->ui16ConversionCount = 250;
        pSensor->ui16ConversionGain = 100;
        pSensor->ui16ProxThreshold = 10;
        pSensor->ui16TouchThreshold = 25;

    etc...

    Does this make sense, or am I still not getting what you are asking?

  • Hi Denis,

    Thanks a lot, I feel a bit stupid seeing the solution was that simple.. It works really well! So know I'll be able to dynamicaly adjust my touch parameters, thanks to you :)

    Have a very nice day.

    Yoann

**Attention** This is a public forum