root / paintboard / code / geiger.c @ 11c945d9
History | View | Annotate | Download (413 Bytes)
1 | 11c945d9 | Julian Binder | #include <avr/io.h> |
---|---|---|---|
2 | #include <avr/interrupt.h> |
||
3 | #include <stdlib.h> |
||
4 | #include "geiger.h" |
||
5 | |||
6 | |||
7 | int16_t count; |
||
8 | int16_t rate; |
||
9 | int16_t ticks; |
||
10 | |||
11 | void geiger_init()
|
||
12 | { |
||
13 | EICRA |= _BV(ISC11) | _BV(ISC10); |
||
14 | EIMSK |= _BV(INT1); |
||
15 | } |
||
16 | |||
17 | void geiger_tick()
|
||
18 | { |
||
19 | ticks++; |
||
20 | if(ticks==100) |
||
21 | { |
||
22 | ticks=0;
|
||
23 | rate = count*3;
|
||
24 | count = 0;
|
||
25 | } |
||
26 | } |
||
27 | |||
28 | int16_t geiger_rate() |
||
29 | { |
||
30 | return (rate==0)?count:rate; |
||
31 | } |
||
32 | |||
33 | ISR (INT1_vect) |
||
34 | { |
||
35 | count++; |
||
36 | } |