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.

CC2640: How to get ADC sampling in CC2640 using Aux Timer0

Part Number: CC2640

Hi,

my requirement is to sample multiple channels (3 channels) at 500 Hz. I have the system running with manual trigger wherein the Sensor controller is called with RTCTick = 131. The resultant frequency is close to 500 Hz (but not quite). 

I am putting down the implementation here. 

# Init Code**************

// Schedule the first execution

fwScheduleTask(1);

# End Init Seq *********************

# Execution Code ******************

// Enable the ADC

adcEnableSync(ADC_REF_FIXED, ADC_SAMPLE_TIME_170_US,ADC_TRIGGER_MANUAL);

//Probe point pulse to check sampling rate

// Pull the GPIO High to indicate start of this sampling phase

gpioSetOutput(AUXIO_O_SAMPLING_PROBE);

for (U16 n = 0; n < SENSOR_OUTPUT_CNT; n++) {

U16 p = n;

// Select ADC input

adcSelectGpioInput(cfg.pAuxioASensorOutput[n]);

// Insert Delay to allow settling

fwDelayUs(150, FW_DELAY_RANGE_200_US);

// Sample and store the ADC value

adcGenManualTrigger();

n = output.head;

adcReadFifo(output.pSamples[n]);

utilIncrAndWrap(n, BUFFER_SIZE; output.head);

if(output.head==0){

fwGenAlertInterrupt();

}

n = p;

}

// Bring the GPIO Down to indicate end of this sampling phase

gpioClearOutput(AUXIO_O_SAMPLING_PROBE);

// Disable the ADC

adcDisable();

// Schedule the next execution

fwScheduleTask(1);

# End Execution Code

There's nothing in the Termination Code. 

This code works. However, I want to get the ADC sampling using AuxTimer0 and I am unable to do it. 

To start with I introduced the StartAuxTimer0(2000) in the init code, hoping that sampling would happen every 2000 us. The code got stuck moment I introduced the following statement in the execution code. Later I read that the adcEnableSync or, adcEnableAsync can't be introduced once StartAuxTimer0 has been started.

adcEnableSync(ADC_REF_FIXED, ADC_SAMPLE_TIME_170_US,ADC_TRIGGER_AUX_TIMER0); 

Later I moved the adcEnableSync statement in Init routine before starting the AuxTimer0. The code ran but the ADC output was fixed and never changed with the input being provided input. I also tried out putting the StartAuxTimer0 in execution code after the adcEnableSync and stopping the AuxTimer0 at the end of the code before disabling the ADC. The code runs but clearly the sampling is not what I desire. And I do understand that the AuxTimer0 has to run continuously to get continuous train of samples and can't be started and stopped.

I have searched a lot to find the right way of implementing this but unfortunately the documentation on this topic is next to nil, Can you help me with a basic implementation of sampling using AuxTimer0, even if its for a single channel.

  • Hello Goutam,
    The sensor controller must be in active mode when using the aux timer 0 trigger. Please refer to the ADC Data Streamer example code in Sensor Controller Studio.
  • Eirik,
    I could get the code to work with your guidance. Thanks a lot.
    I am however having one issue.

    I call the Sensor Controller Code once using the following sequence:
    scifOsalInit();
    scifOsalRegisterCtrlReadyCallback(scCtrlReadyCallback);
    scifOsalRegisterTaskAlertCallback(scTaskAlertCallback);
    scifInit(&scifDriverSetup);
    SCIF_RESULT_T rc = scifExecuteTasksOnceNbl(BV(SCIF_ADC_DATA_STREAMER_TASK_ID));

    This runs fine. I get alert notifications in the main loop and I process the same.
    I clear the alert using scifClearAlertIntSource(), grab all the data and finally acknowledge the Alertevents using scifAckAlertEvents().


    To stop the Sensor controller, I do the following:
    /* Stop Sensor Controller Task */
    scifStopTasksNbl(BV(SCIF_ADC_DATA_STREAMER_TASK_ID));
    scifResetTaskStructs(BV(SCIF_ADC_DATA_STREAMER_TASK_ID), SCIF_STRUCT_INPUT);

    // Wait for task to terminate
    scifWaitOnNbl(100000);

    I am not sure whether it is stopping the sensor controller but it doesn't hurt me here.

    The place where I get stuck is when I try to re-start the sensor controller for one more session of capture. The scifExecuteTasksOnceNbl() this time returns a value of 1 which means SCIF_NOT_READY (previous non-blocking call is still running)

    Can you help point out the error in this.
  • Try to place
    scifResetTaskStructs(BV(SCIF_ADC_DATA_STREAMER_TASK_ID), SCIF_STRUCT_INPUT);
    after
    scifWaitOnNbl(100000);
  • Thank you. It works. I had to increase the Wait Period. Thanks a lot.

    Goutam