Last active
October 12, 2017 11:03
-
-
Save heborras/09cb302eedfb100eca4fbe17489bded0 to your computer and use it in GitHub Desktop.
Event/Interrupt recording firmware for the Arduino DUE.
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
/* | |
Description: | |
Event/Interrupt recording firmware for the Arduino DUE. | |
The firmware can record events from different detectors with sufficent precision. | |
The resulting output can be recorded to calculate coincidence rates. | |
Usage: | |
Set pins that are supposed to be used as detection interrupts. | |
Attach interrupts to those pins and give them fitting names. (See example further down) | |
Flash firmware to DUE. | |
Record serial output with: https://gist.github.com/HenniOVP/3ee85aee16575391f46451dbd566b0ef | |
Analyze the recorded serial output with: https://gist.github.com/HenniOVP/b48d752b523b778235a2a62b49d0a2f5 | |
*/ | |
int LED_pin = 13; | |
int PMT_pin = 12; | |
int SiPM_pin = 53; | |
int GM_pin = 26; | |
void printTimeAndPin(int pin, String name){ | |
// print when and which pin was interrupted | |
unsigned long mil = millis(); | |
unsigned long mic = micros(); | |
Serial.print("T="); | |
Serial.print(mil); | |
Serial.print(":"); | |
Serial.print(mic); | |
Serial.print(";P="); | |
Serial.print(pin); | |
Serial.print(";n="); | |
Serial.println(name); | |
} | |
void setup() { | |
// setup pins as interrupt pins | |
pinMode(PMT_pin, INPUT); //set the interrupt pin for trigger as high impedance, probably not required | |
pinMode(SiPM_pin, INPUT); //set the interrupt pin for trigger as high impedance, probably not required | |
pinMode(GM_pin, INPUT); //set the interrupt pin for trigger as high impedance, probably not required | |
attachInterrupt(digitalPinToInterrupt(PMT_pin), [=] () {printTimeAndPin(PMT_pin, "PMT");}, RISING); | |
attachInterrupt(digitalPinToInterrupt(SiPM_pin), [=] () {printTimeAndPin(SiPM_pin, "SiPM");}, RISING); | |
attachInterrupt(digitalPinToInterrupt(GM_pin), [=] () {printTimeAndPin(GM_pin, "GM");}, RISING); | |
// led pin | |
pinMode(LED_pin, OUTPUT); | |
//setup the serial for debug | |
//Serial.begin(9600); | |
// increase baud rate to handle serial prints faster | |
// this as well decreases the chance of interrupt collisions | |
Serial.begin(115200); | |
} | |
void loop() { | |
// blink to show activity | |
delay(100); | |
digitalWrite(LED_pin, HIGH); | |
delay(50); | |
digitalWrite(LED_pin, LOW); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment