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.

ADC/Sensor controller: Sample multiple analog pins at different frequencies

Other Parts Discussed in Thread: CC2650

Hi everyone

My application needs to collect data from three different sources:

- Micophone (at the moment the light sensor on the evaluation board): I need to take a sample every 70us

- Temperature: A few (ca 5) times per second is enough

- Battery voltage: A few times per second is enough

My system:

CC2650, SmartRF06EB

At the moment, this is the code for the sensor controller:

// Power up the light sensor and wait for it to get ready

gpioSetOutput(AUXIO_O_ALS_POWER);

fwDelayUs(1000, FW_DELAY_RANGE_1_MS);

// Select ADC input

adcSelectGpioInput(AUXIO_A_SENSOR_OUTPUT);

// Enable the ADC

adcEnableAsync(ADC_REF_FIXED, ADC_TRIGGER_AUX_TIMER0);

adcStartAuxTimer0Trigger(70);

// Loop until the application sets the exit flag

while (state.exit == 0) {

// Wait for the next ADC sample and store it

U16 n = state.head;

adcReadFifo(state.newValue);

if (state.samplingEnabled == 1) {

output.pSamples[n] = state.newValue;

// Update the head index

utilIncrAndWrap(n, BUFFER_SIZE; state.head);

// Calculate the number of samples currently stored

S16 count = state.head - state.tail;

if (count < 0) {

count += BUFFER_SIZE;

}

if (count >= 760) {

state.tail = 0;

state.head = 0;

state.samplingEnabled = 0;

adcFlushFifo();

state.overflow = state.overflow + 1;

}

} else {

adcFlushFifo();

}

}

At the moment I sample only the values from the light sensor/micophone. How can I modify this code such that a few times per second I also take a sample from the temperature sensor and the battery voltage without disturbing the sampling instances of the sound/light signal?

Ideas:

- Create a second task in sensor controller studio that is responsible for the temperature/battery voltage measurement.

- I think that I am supposed to use adcSelectGpioInput(...), but won't that disturb the sound measurements?

Can anybody give me a hint how to solve this problem. I did not found an example/explaination how to handle it in the data sheet, technical reference or the sensor controller studio help.

  • Hello Fabien,

    A secondary task only run after the previous task is complete/ended. All tasks must run until completion before a new task is started.

    You can try to set up a if-statement on the count variable to trigger the temp/batt reads and try to switch input pin and issue a manual trigger while you let the aux timer trigger run. If you can do this in less than 70 us it might work.

    ...
    adcSelectGpioInput(AUXIO_A_XXXX)
    // Sample the sensor and store the ADC value
    adcGenManualTrigger();
    adcReadFifo()
    adcSelectGpioInput(AUXIO_A_SENSOR_OUTPUT); ...
    
  • Thank you for the answer. I was a little afraid in doing it as you described because there is no guarantee that there is not yet an additional sample added to the FIFO when we switch the input, but I was surprised that it worked great! Now I can sample data from the microphone at high rate and from other sensors at very low rate simultaneously.
  • Great stuff!