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.

CC2640R2F: Sensor Controller COMPA reference switching

Part Number: CC2640R2F

Tool/software:

We are using Sensor Controller to measure a capacitive sensor. Simplified schematic:

Switches S1/S2 represent COMPA Ref. MUX, C1 is our sensor. Measurement is similar to https://dev.ti.com/tirex/explore/node?node=A__AAxJaXIOcaqqfHxSDzQv8g__com.ti.SIMPLELINK_ACADEMY_CC2640R2SDK__7unKOT8__LATEST, but instead of creating ref voltage using resistor and 2uA current source, we set the voltages externally. We have observed that this gives us lower noise in the measured data, compared to TI example configuration. High level Sensor Controller code flow:

  1. Configure TDC to start and stop counting on COMPA output tdcSetTriggers(TDC_STARTTRIG_COMPA_HIGH, TDC_STOPTRIG_COMPA_HIGH, 1);
  2. Release ISRC so the voltage across capacitor starts rising
  3. Wait for COMPA to trigger the first time
  4. Change COMPA reference source compaSelectGpioRef(AUXIO_AXS_REF_3V);
  5. Wait until TDC is done

I am concerned about compaSelectGpioRef(AUXIO_AXS_REF_3V);, API description https://software-dl.ti.com/lprf/sensor_controller_studio/docs/cc13x0_cc26x0_help/html/compa__0.html#compa-0-compaselectgpioref says Any previously used reference source is disconnected before the GPIO pin is connected. Does this mean that ref input is floating during the switch? Can a floating COMPA ref input trigger a false positive on COMPA output?

Is the "break-before-make" a feature of the COMPA MUX or Sensor Controller library? For our use case, "make-before-break" would work, shorting REF1 and REF2 is not an issue.

  • 1. Any input GPIO should always be pulled up or down internally or externally. "Disconnected" in this context just means that the switch is toggled off but the GPIO is still pulled up to prevent a floating input.

    2. BBM is built into the COMPA library. I will double check with software team.

  • 1. Any input GPIO should always be pulled up or down internally or externally. "Disconnected" in this context just means that the switch is toggled off but the GPIO is still pulled up to prevent a floating input.

    Thank you for the note on what is happening on GPIO side. Can you please share what is happening on the COMPA ref input side? Is COMPA ref input left floating momentarily during compaSelectGpioRef? I would assume COMPA output is undefined if COMPA ref input is floating and could trigger premature TDC stop.

  • If the GPIO on ref input is pulled up or down, then it will always be 0 or VDD. This is only possible if the switch is placed between the voltage source and the GPIO.

  • I think we have some confusion, I am not asking about GPIO side. I want to know what happens to COMPA ref (negative input) internally when it is switched from one input to another with  compaSelectGpioRef. I have marked the location in the COMPA block diagram from software-dl.ti.com/.../compa__0.html.

    Please see improved sample code:

    compaEnable();
    compaSelectGpioRef(AUXIO_AXS_REF_025V);
    isrcEnable(BV_ISRC_CURR_4P5U); //Current is found in page 1336 of user_guide
    
    // Select 2 x 48 MHz from RCOSC_HF as TDC counter clock source
    tdcSetCntSource(TDC_CNTSRC_96M_RCOSC); //96 M TDC clock FTW
    
    // Enable the TDC with start trigger on ISRC reset release and stop trigger on COMPA
    tdcSetTriggers(TDC_STARTTRIG_COMPA_HIGH, TDC_STOPTRIG_COMPA_HIGH, 1); // (#startTrigger, #stopTrigger, ignoredStopTriggerCount). ignoredStopTriggerCount - Number of stop triggers to ignore before stopping the counter (0-65535)
    tdcEnable();
    
    // Select COMPA input/ISRC output
    compaSelectGpioInput(AUXIO_AXD_CAP_POS);
    
    
    // Prepare the TDC and trigger start of measurement
    tdcArm(TDC_START_ASYNC);
    fwDelayUs(50,FW_DELAY_RANGE_100_US);
    isrcRelease(AUXIO_AXD_CAP_POS);
    
    // Wait for the COMPA output to go high, and then switch the reference pin.
    
    //Add timeout for this first treshold using TIMER 0
    
    
    timer0Start(TIMER0_MODE_SINGLE, 9600, 0);
    U16 first_th_reached=0;
    U16 first_timeout=0;
    U16 time_took_to_reach_th1=0;
    do {
        // Check whether the timeout has occured
        U16 timer0IsRunning;
        timer0CheckState(timer0IsRunning);
        first_timeout = timer0IsRunning ^ 0x0001; //XOR, if both are 1 it results in 0 (while timer is running), if it is timeout it will return 1
        
        // Check whether the interrupt has occurred
        compaGetOutput(first_th_reached);
        
        U16 done = first_th_reached | first_timeout;
    } while (done == 0);
    timer0Stop();
    
    compaSelectGpioRef(AUXIO_AXS_REF_3V);
    
    U16 isTdcDone;
    tdcWaitUs(700); //Max charge time in us for now
    tdcCheckDoneEv(isTdcDone);
    
    
    // Re-clamp the pin to ground
    isrcClamp(AUXIO_AXD_CAP_POS);

    Is the COMPA output going to stay stable when compaSelectGpioRef is called second time? According to API description it seems that COMPA ref input will float momentarily.

  • Thank you for clarifying. The COMPA output can potentially be unstable during any transition where the input is floating, but typically adding a delay to allow ref input to switch in and the COMPA output to stabilize resolves this issue. This is the cheapest, quickest solution.

  • Not sure if delay will be helpful in this configuration where COMPA output is used to start and stop TDC. TDC is configured to start on first COMPA output high and stop on the second COMPA output high (line 9 in the example). Can you please clarify how delay would help to prevent accidental premature stopping of TDC?

  • Let me run this by my team. I'll have a response by the end of the week.

  • I'll need to loop in the software team to see if it is possible to do a make-before-break since that would be the best solution for you since you are ok with it.

    Otherwise it's a fight between hysteresis, settling time and TDC speed.

  • Would it be possible to enable 2uA current source to make sure it saturates the COMPA ref input during the break-before-make switch? From COMPA block diagram it seems that 2uA current source is independent from muxes. Sensor Controller Studio does not support that at the moment, but I would assume it is possible with a couple lines of Sensor Controller assembly code.

  • This is the response from the software team:

    The compaSelectGpioRef  function can be changed by copying it to the user space of Sensor Controller Studio. You can also make your own variant by modifying the name of the function (or procedure as it is called in Sensor Controller Studio).
     
    For example:
    1. Copy <SCStudio installation directory>/proc_defs/compa_select_gpio_ref.* (1 prd and 2 asm files) to the user space:
               C:\Users\<user>\Documents\Texas Instruments\Sensor Controller Studio\proc_defs\.
    2. Modify content.
      Alternatively rename files and the name of the procedure given inside the files. Then you get your own variant that will be available to use from SCStudio. Also remember to rename the label used in the assembly files.

    As for saturating the COMPA, it was not validated under such condition so is it not known how long it can survive saturation. I'll need to check.

  • I would assume COMPA output is undefined if COMPA ref input is floating and could trigger premature TDC stop.

    Testing confirmed that COMPA can be triggered prematurely and TDC will output some low value in the range of 31 - ~500 instead of normal value in the range 14-24k. Interestingly, the frequency this happens depends on COMPA positive input noise and how fast COMPA reference is switched to a higher level.

    The sample code I shared results in 1 glitch every ~20k samples in our noisy setup. With code improvements (clamp AUXIO_AXS_REF_025V to VDD before reference switch, enable 2uA current source to saturate COMPA ref input, remove timeout checking) I got 1 glitch every ~1M samples. To avoid this COMPA reference switch instability, we will modify the design to include an external comparator. COMPA with 0.25V reference will start the TDC and external comparator with 3V reference will stop TDC.

    By the way, thank you for pointing out how to create custom functions for Sensor Controller, it helped a lot while debugging this.