Arduino Due Analog Read / Oscilloscope HELP

Hello Guys,

I got a Problem:

I wanna read analog Singlas from a function generator and want to print them into a graph in LabView

So it should be a small oscilloscope...

i try to write a Programm for the Arduino but it doesn't work correctly :confused: i don't get the right values

Can anyone help me or did anyone write such a Program before ?

Here the code:

char data[1000];

void setup(){
Serial.begin(115200);
ADC->ADC_MR |= 0x80; //Free running modus
ADC->ADC_CHER = 0x80 // ADC auf A0 = Pin 7
analogReadResolution(10); // 10 bit auflösung wie bei arduino uno...für gleiche Testzwecke
}
void loop(){

for (int i;i<1000;i++){
while((ADC->ADC_ISR & 0x80)==0); //Konversion
data[i]=analogRead(A0);
Serial.println(data[i]);
    }
}

Thanks for your help :slight_smile:

You don't say in what way it "doesn't work" but one obvious problem is that you are storing ints returned by analogRead() into an array of chars.

As gutbag says, your character array stores 8 bit values and your ADC is set for 10 bit resolution. You will have to use a 16 bit array, signed or unsigned integer.

Also realize that your Serial,println() will cause a delay equal to the time to send the byte (will need to be two bytes) of data on the serial line. So you will miss a number of samples while this happens.

Since you are using Serial.println() there will be an extra character appended, the end-of-line character which also causes the serial buffer to flush.

If you need to examine each sample from your ADC, without missing the ones during serial transmission, you may have to store a number of samples in the array, then dump the arrary with the Serial.println in a separate loop.

A reminder, the ADC accepts signals for 0 VDC to the Analog Reference Voltage you have configured. You cannot supply it with voltage less than 0 VDC, so if you function generator is giving you AC signals you will have to bias them to fall withing 0- reference voltage.

thanks for the answers till now :slight_smile:

I correct my program and now it seems to work....

but my "problem" now is, that I wanna read 6 analog pins one by one..... so that I get for example
5000 values from A0 , then 5000 from A1 and so on...

Did someone know how can I realize that :confused: ?

here is my code till now:

unsigned long data[5000];

void setup() {        
  Serial.begin(115200);  
  adc_init(ADC, SystemCoreClock, 21000000UL, ADC_STARTUP_FAST);
  ADC->ADC_MR |= 0x80;  //set free running mode on ADC
  ADC->ADC_CHER = 0x80; //enable ADC on pin A0
  analogReadResolution(8);
}

void loop() {

  unsigned int i;
 

  for(i=0;i<5000;i++){
    while((ADC->ADC_ISR & 0x80)==0); // wait for conversion
    data[i]=ADC->ADC_CDR[7]; //get values
  }
 

  for(i=0;i<5000;i++) {
    Serial.println(data[i]);
  }
  
delay(100);  
}

You need a multiplexer and some code: See this tutorial

http://playground.arduino.cc/Learning/4051

Can I use it also for my arduino Due ?!