Skip to content

Instantly share code, notes, and snippets.

@pingud98
Last active September 12, 2019 19:34
Show Gist options
  • Save pingud98/00b1dd5ff8878aea165e to your computer and use it in GitHub Desktop.
Save pingud98/00b1dd5ff8878aea165e to your computer and use it in GitHub Desktop.
Arduino Due Fast ADC script
unsigned long start_time;
unsigned long stop_time;
unsigned long values[2000];
void setup() {
Serial.begin(115200);
REG_ADC_MR = 0x10380180; // change from 10380200 to 10380180, 1 is the PREESCALER and 8 means FREERUN
ADC -> ADC_CHER = 0x03; // enable ADC on pin A0
}
void loop() {
unsigned int i;
//reads in on pins 6 and 7
start_time = micros();
for(i=0;i<1000;i++){
while((ADC->ADC_ISR & 0x03)==0); // wait for conversion
values[i]=ADC->ADC_CDR[0];
values[i+1000]=ADC->ADC_CDR[1];//get values
}
stop_time = micros();
Serial.print("Total time: ");
Serial.println(stop_time-start_time);
Serial.print("Average time per conversion: ");
Serial.println((float)(stop_time-start_time)/2000);
Serial.println("Values: ");
for(i=0;i<1000;i++) {
Serial.print(values[i]);
Serial.print(", ");
Serial.println(values[i+1000]);
}
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment