From a007524389c0539a92be5d4dc7a87910a6270108 Mon Sep 17 00:00:00 2001 From: James Devine Date: Sun, 13 Sep 2015 16:23:58 +0200 Subject: [PATCH] --- dualchannel.ino | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 dualchannel.ino diff --git a/dualchannel.ino b/dualchannel.ino new file mode 100644 index 0000000..9daad52 --- /dev/null +++ b/dualchannel.ino @@ -0,0 +1,87 @@ +//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