/** * Radiation counting */ #include "radiation.h" #include "time_base.h" #include "global_state.h" #include "iopins.h" #include #include #include #include #define MEAS_BIN_COUNT 120 typedef uint8_t meas_bin_t; #define MEAS_MAX_COUNT 255 /// measurements in the last X seconds static volatile meas_bin_t measurements[MEAS_BIN_COUNT]; /// Currently active measurement bin, increments once per second static volatile uint8_t meas_bin = 0; // geiger tube pin change interrupt ISR(INT0_vect) { if (measurements[meas_bin] < MEAS_MAX_COUNT) { measurements[meas_bin]++; } req_update_display = true; } void second_callback_irq() { meas_bin++; if (meas_bin >= MEAS_BIN_COUNT) { meas_bin = 0; } measurements[meas_bin] = 0; req_update_display = true; } void init_radiation() { // clear the measurement buffer memset((void*) measurements, 0, sizeof(measurements)); as_input(D2); // using INT0 - arduino pin D2 EICRA = _BV(ISC01) | _BV(ISC00); // rising edge EIMSK = _BV(INT0); }