You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
52 lines
1.1 KiB
/**
|
|
* Radiation counting
|
|
*/
|
|
|
|
#include "radiation.h"
|
|
#include "time_base.h"
|
|
#include "global_state.h"
|
|
#include "iopins.h"
|
|
|
|
#include <avr/interrupt.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
#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);
|
|
}
|
|
|