//this works from the electronics crate, reads out Ch 6 and Ch7 fast enough, peak samples generally occur at 4th position on readback. //Shotky diodes are used to prevent negative voltage hurting the ADC. int x; // read value int adcloopctr; unsigned long values[200]; const int eventtrigger = 49; boolean eventhappened = false; int sampledepth = 10; int printctr = 0; int readoutctr; void setup() { // analogReference(INTERNAL); pinMode(eventtrigger, INPUT); attachInterrupt(eventtrigger, monkey, FALLING); Serial.begin(115200); // initialize the serial port: 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 A6 and A7 eventhappened = false; adcloopctr=0; Serial.println("Alive"); } void loop() { //unsigned long t = micros(); // init time an elapsed time, in micro seconds //for(i = 0; i < 1000; i++) { // instrucction to measure while((ADC->ADC_ISR & 0x3)==0); // wait for conversion values[adcloopctr+100] = ADC->ADC_CDR[0]; // read value A0 values[adcloopctr] = ADC->ADC_CDR[1]; // read value A0 if (eventhappened){ //Serial.println("Event"); //for (int printctr = adcloopctr+1; printctr+1 < sampledepth+adcloopctr; printctr++) { //Serial.print(printctr); //Serial.print(", "); //if (printctr > sampledepth){ //Serial.println(values[(printctr)]); //Serial.println(values[(printctr)]); //} //printctr = ++printctr % sampledepth; readoutctr=10; for (int firsthalf=adcloopctr+1; firsthalf