ADC and circular buffer

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
mculover
Posts: 26
Joined: Fri Dec 10, 2010 2:27 pm

ADC and circular buffer

Post by mculover »

Hi Giovanni,

For ADC with circular buffer option, It's never end operation.
This is right ?...

For this reason, In main.c of testhal, Should not run to adcStop(&ADCD1).

Code: Select all

static msg_t adc_continuous_thread(void *p){

  (void)p;
  palSetGroupMode(IOPORT3,
                  PAL_PORT_BIT(0) | PAL_PORT_BIT(1),
                  PAL_MODE_INPUT_ANALOG);
  adcStart(&ADCD1, &adccfg);
  adcStartConversion(&ADCD1, &adcgrpcfg, samples,
                     ADC_GRP1_BUF_DEPTH, adccallback);
  adcWaitConversion(&ADCD1, TIME_INFINITE);
  adcStop(&ADCD1);
  return 0;
}



Thanks for advance.
mculover
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: ADC and circular buffer

Post by Giovanni »

Hi,

Correct, it does not terminate unless some other thread or a callback invokes adcStopConversion(), note that the main() thread does that after pressing the board button.

Giovanni
mculover
Posts: 26
Joined: Fri Dec 10, 2010 2:27 pm

Re: ADC and circular buffer

Post by mculover »

Hi Giovanni,

In same file.

What is purpose for callback function ?.
It's never use nx and ny any more.

Code: Select all


size_t nx = 0, ny = 0;
static void adccallback(adcsample_t *buffer, size_t n) {

  if (samples == buffer) {
    nx += n;
  }
  else {
    ny += n;
  }
}


Thanks for advance.
mculover
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: ADC and circular buffer

Post by Giovanni »

Those are not used anywhere, just incremented for debug, each variable is incremented every time half of the circular buffer is filled with samples.

The ADC callback is usually used for "streaming processing", the ADC performs a continuous circular conversion of a set of channels and the CPU elaborates the samples within the callback.

For example you may want to transmit over Ethernet or SPI the sampled data in real time or drive a PWM with the results, you can do this without have to have a dedicated thread.

Giovanni
mculover
Posts: 26
Joined: Fri Dec 10, 2010 2:27 pm

Re: ADC and circular buffer

Post by mculover »

Thanks you very much for help.
:D
mculover
Post Reply