Page 1 of 1

Multiple ADC Samples in one call?

Posted: Fri Oct 10, 2014 12:59 am
by JetForMe
I'm trying to grab multiple samples from two channels at a specified frequency. I've got this code. But I only get one sample (of each channel), and then nothing but zero. I tried adding the timer trigger flag and setting the frequency to 1000, but that didn't work, either. Can I even do what I'm trying to do?

Code: Select all

const size_t    kADCSampleBufferDepth                       =   16;
adcsample_t     sADCBuffer[kADCSampleBufferDepth][2];

void
loop()
{
    mADCGroup.circular = true;
    mADCGroup.num_channels = 2;
    mADCGroup.end_cb = NULL;
    mADCGroup.error_cb = NULL;
    mADCGroup.channelselects = (1 << 4) | (1 << 7);
    mADCGroup.trigger = ADC_TRIGGER_SOFTWARE;
    mADCGroup.frequency = 0;

    while (looping)
    {
        //  Read the ADCs…
       
        adcConvert(&ADCD1, &mADCGroup, (adcsample_t*) sADCBuffer, kADCSampleBufferDepth);
       
        //  Average the samples…
       
        uint16_t    rawTemp = 0;
        uint16_t    rawBatt = 0;
        for (size_t i = 0; i < kADCSampleBufferDepth; ++i)
        {
            rawTemp += sADCBuffer[i][0];
            rawBatt += sADCBuffer[i][1];
            sDebug.log("Sample %u: %5u %6u   %5u %6u\n",
                            i,
                            sADCBuffer[i][0], rawTemp,
                            sADCBuffer[i][1], rawBatt);
        }
        rawTemp >>= 2;
        rawBatt >>= 2;
   
        //  do stuff, sleep, etc.
    }
}

Re: Multiple ADC Samples in one call?

Posted: Fri Oct 10, 2014 8:21 am
by Giovanni
It could be a bug in the driver, which platform is it? it would be a good idea to move this into the appropriate forum.

Giovanni

Re: Multiple ADC Samples in one call?

Posted: Fri Oct 10, 2014 8:42 am
by JetForMe
AT91SAM7