Go Down

Topic: Arduino DUE ADC serial streaming behave differently to Windows and Linux (Read 1 time) previous topic - next topic

doushicai

Hi all,

I want to use Arduino DUE streaming two ADC channels (A0 and A1) to raspberry pi and make the raspberry pi log and store the data.
The ADC output resolution is 16 bit with around 30 KHz. The data is streaming out through USB virtual serial port /dev/ttyACM0.

The weird problem I have now is when I testing in Windows machine and log with putty, every thing work beautifully as I expect.

However, when I testing in the raspberry pi and log with putty, the data is just go cray from time to time and not stable.
I also tested in other Linux machine like ubuntu, the data is flawed like the pi.
So, I am very confused why this difference happened.
Since the code in Arduino is never changed during all the test, so the problem is from Linux not Arduino?

There are attachments of my test results, the A0 is loging 1kHz (0.5v to 2.5v ) sin wave and A1 is loging constant 3.3v.

 

doushicai

For anyone what to further look into this problem, this is the code I am using modified from stimmer's code

#undef HID_ENABLED

volatile int bufn,obufn;
uint16_t buf[4][256];   

void ADC_Handler(){   
 int f=ADC->ADC_ISR;
 if (f&(1<<27)){
  bufn=(bufn+1)&3;
  ADC->ADC_RNPR=(uint32_t)buf[bufn];
  ADC->ADC_RNCR=256;
 }
}

void setup(){
 SerialUSB.begin(0);
 while(!SerialUSB);
 pmc_enable_periph_clk(ID_ADC);
 adc_init(ADC, SystemCoreClock, ADC_FREQ_MIN/2, ADC_STARTUP_NORM);
 ADC->ADC_MR |=0x80;

 ADC->ADC_CHER = ADC_CHER_CH7|ADC_CHER_CH6;
 ADC->ADC_MR |=0x80000000;   
 
 ADC->ADC_SEQR1=0x76000000;
 ADC->ADC_SEQR2=0x0000;

 NVIC_EnableIRQ(ADC_IRQn);
 ADC->ADC_IDR=~(1<<27);
 ADC->ADC_IER=1<<27;
 ADC->ADC_RPR=(uint32_t)buf[0];   
 ADC->ADC_RCR=256;
 ADC->ADC_RNPR=(uint32_t)buf[1];
 ADC->ADC_RNCR=256;

 bufn=1;
 obufn=0;
 ADC->ADC_PTCR=1;
 ADC->ADC_CR=2;
}

void loop(){
 
 while((obufn+1)%4==bufn);
 SerialUSB.write((uint8_t *)buf[obufn],512);
 obufn=(obufn+1)&3;   
}

Go Up