Created
September 13, 2015 14:23
-
-
Save pingud98/69daa8d524ec504046da to your computer and use it in GitHub Desktop.
Cosmic Pi Dual Channel Readout
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
//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<sampledepth; firsthalf++) | |
{ | |
Serial.print(readoutctr); | |
Serial.print(", "); | |
Serial.print(values[firsthalf]); | |
Serial.print(", "); | |
Serial.println(values[firsthalf+100]); | |
readoutctr--; | |
} | |
for (int secondhalf=0; secondhalf<adcloopctr+1; secondhalf++) | |
{ | |
Serial.print(readoutctr); | |
Serial.print(", "); | |
Serial.print(values[secondhalf]); | |
Serial.print(", "); | |
Serial.println(values[secondhalf+100]); | |
readoutctr--; | |
} | |
eventhappened = false; | |
//delay(200); | |
} | |
adcloopctr++; | |
if (adcloopctr==sampledepth) { | |
adcloopctr=0; | |
} | |
} | |
void monkey() | |
{ | |
//Serial.println("trigger"); | |
eventhappened = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment