Last active
September 12, 2019 19:34
-
-
Save pingud98/00b1dd5ff8878aea165e to your computer and use it in GitHub Desktop.
Arduino Due Fast ADC script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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