A/D conversion and serial transmission with arduino Due

Hello guys, I’m using this code, but it is causing a discontinuity for each block of 1000 points. I am sure that this discontinuity is caused by the serial transfer time.

How could I correct this, to obtain a continuous transmission without loss of points during the discontinuity at the end of each block of 1000 points?

follow my code:

unsigned long k = 1000 ; // buffer size
unsigned long values[1000];

void setup() {
ADC->ADC_MR |= 0x80; // enable continuous acquisition
ADC->ADC_CHER = 0X80; // Active PIN A0 INPUT
void loop() {
unsigned int i;
while((ADC->ADC_ISR & 0x80)==0); // wait for conversion
values*=(ADC->ADC_CDR[7]); // adds the value to the buffer*

  • }*

  • delayMicroseconds(1);*

  • for(i=0;i<k;i++)*
    _ { Serial.println(values*); }} // Plot buffer*_

The best way to log smoothly ADC conversions is with a PDC DMA. Search in the DUE sub forum for example sketches of ADC conversions and DMA. Morover, IMO it's clearer to use uint16_t type variables for ADC conversions rather than long type.

Moreover, the ADC peripheral needs some calibration to improve accuracy:

Some general rules to improve ADC conversions:

  • Power the DUE with a powerbank since power thru the USB cable from a PC is unstable,
  • Pay attention to wiring,
  • Put a signal conditioning circuit on the analog input pin,
  • Oversample and average ADC conversions,
  • Write your code with PDC DMA (example sketches are provide in the DUE sub forum ADC with direct register programming).