Multiple ADC Samples in one call?

ChibiOS public support forum for topics related to the Atmel AT91SAM7x family of micro-controllers.

Moderator: inmarket

JetForMe
Posts: 99
Joined: Mon Jan 31, 2011 8:12 am

Multiple ADC Samples in one call?

Postby JetForMe » Fri Oct 10, 2014 12:59 am

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.
    }
}

User avatar
Giovanni
Site Admin
Posts: 11220
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 399 times
Been thanked: 333 times
Contact:

Re: Multiple ADC Samples in one call?

Postby Giovanni » Fri Oct 10, 2014 8:21 am

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

JetForMe
Posts: 99
Joined: Mon Jan 31, 2011 8:12 am

Re: Multiple ADC Samples in one call?

Postby JetForMe » Fri Oct 10, 2014 8:42 am

AT91SAM7


Return to “AT91SAM7x Support”

Who is online

Users browsing this forum: No registered users and 1 guest