Fast-ADC-CH6-CH7-00b1dd5f/Fast ADC CH6 CH7
2015-07-17 08:14:55 -07:00

36 lines
No EOL
956 B
Text

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);
}