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.

LAUNCHXL-CC26X2R1: Config the ADC sampling rate in sensor control

Part Number: LAUNCHXL-CC26X2R1

Hi

We would like to obtain the ADC value with a sampling rate of 256 Hz.

Regarding the method #1, we use the RTC tick interval to set the Sensor Control task tick interval. When Sensor Control collects the 256 ADC samples, it will notify the main application, in the main application, we check the notification time, it always keep  1 Second.

//Main application 
uint32_t rtc_Hz = 256;  // 256Hz RTC
scifStartRtcTicksNow(0x00010000 / rtc_Hz);

Regarding the method #2, we use the timer0 to trigger ADC.
//Sensor Control 

adcEnableSync(ADC_REF_FIXED, ADC_SAMPLE_TIME_2P7_US, ADC_TRIGGER_AUX_TIMER0);
// Generate timer events at every 3906.25 us(1/256)
timer0Start(TIMER0_MODE_PERIODICAL, 46875, 1);

When Sensor Control collects the 256 ADC samples, it will notify the main application, in the main application, we check the notification time, it always keep 998 mS.

Regarding Sensor Control timer, how to get the accurate time? do you have any suggestions to us???

Thanks.

BR

Trevor

  • Hi Trevor,

    Could you specify which sensor controller example you are using?

    I have asked a Sensor Controller expert to comment.

    Best regards,

  • Hi Trevor,

    Timer0 runs on the HF clock which in turn could be sourced wither from the RCOSC or the XTAL depending on the application. As such, the accuracy of it could be a bit off compared to the RTC (which typically always runs on the XTAL), especially if you use the RCOSC. 

    This means that you will get a more precise timer using the RTC approach compared to the Timer0 one. Alternatively, you could try to use Timer2 on the Sensor Controller as this allows you to set the clock source to SCLK_LF which would be the same as sourced to the RTC.

  • Hi M-W,

    We follow your suggestion to use Timer2 as the sampling source, but still can get the accurate time(sampling rate).

    Please refer to the following configuration for Timer2 and screenshot.

    //Initialization Code
    timer2SetClockSource(TIMER2_CLOCKSRC_HFDIV2);
    timer2WaitForClockSource()
    
    timer2SetInitCmpValue(3,125);  //256Hz = 3.90625ms , 125 = 3.90625 * 32
    timer2CfgCcChannel(3,TIMER2_CCMODE_SET_ON_CMP,1 << TIMER2_EV_ID3); //Event handler event
    
    timer2SetInitCounterTarget(125); //256Hz = 3.90625ms , 125 = 3.90625 * 32
    
    // Switch Timer 2 to LF clock and start it
    timer2SetClockSource(TIMER2_CLOCKSRC_LF);
    timer2WaitForClockSource();
    timer2StartWithTarget(TIMER2_CNTRMODE_UP_REP);
    evhSetupTimer2Trigger(0,3,1,EVH_TIMER2_TRIG_ON_EDGE);
    
    
    //Event Handler A Code
    // Sample the sensor ...
    adcSelectGpioInput(AUXIO_A_ADC_INPUT);
    adcEnableSync(ADC_REF_FIXED, ADC_SAMPLE_TIME_2P7_US, ADC_TRIGGER_MANUAL);
    adcGenManualTrigger();
    adcReadFifo(output.adcValue);
    
    
    timer2ClearEvent(TIMER2_EV_ID3);
    
    state.cnt += 1;
    if(state.cnt == 256){
        fwGenAlertInterrupt();
        state.cnt = 0;
    
    }
    // Disable the ADC
    adcDisable();
    
    // Setup the next wake-up trigger
    evhSetupTimer2Trigger(0,3,1,EVH_TIMER2_TRIG_ON_MATCH);

    The following screenshot is RTC-Based Execution Scheduling, you could compare with Timer2.

    Do you have any suggestions to us?

    Thanks.

    BR

    Trevor

  • Hi Trevor,

    Assuming a 32.768 kHz LF source, then I would expect you to use the compare value 128.

    1 / 256 = 3.90625 ms as you stated above, but 125 * ( 1 / 32768 ) = 3.8146973 while 128 * (1 / 32768 ) = 3.90625.

    This means that 256 samples if 125 gives you 0.9766 s (ish) which is close to what you are seeing. 256 samples at a compare value of 128 should give you 1s.

  • Hi M-W,

    Thanks for your help. But if we set the compare value to 128, we still can't get the accurate time(sampling rate).

    Please see the following screenshot, the compare value is 128:

     

    However, if the compare value is set to 127, it looks like that the sampling rate is accurate.

    Please see the following screenshot, the compare value is 127:

    Do you have any comments for this result?

    Thanks.

    BR

    Trevor

  • Hi Trevor,

    Yes, 127 seems to be correct as we need to "zero" align it (0 -> 127 = 128), I forgot this in the previous post. 128 is basically being of by 1 tick, or 3.05*256 = ~8ms just as you could see in your test.

  • Hi M-W.

    Thanks for your help.

    BR

    Trevor