Page 1 of 1

ADC and circular buffer

Posted: Sun Jan 16, 2011 12:41 pm
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

Re: ADC and circular buffer

Posted: Sun Jan 16, 2011 2:23 pm
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

Re: ADC and circular buffer

Posted: Sun Jan 16, 2011 3:16 pm
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

Re: ADC and circular buffer

Posted: Sun Jan 16, 2011 3:40 pm
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

Re: ADC and circular buffer

Posted: Sun Jan 16, 2011 3:55 pm
by mculover
Thanks you very much for help.
:D
mculover