root / trunk / code / projects / diagnostic_station / station / hardware_dynamos.c @ 1929
History | View | Annotate | Download (896 Bytes)
1 | 1251 | deffi | #include "hardware_dynamos.h" |
---|---|---|---|
2 | 1183 | deffi | |
3 | volatile int16_t count_l=0, count_r=0; |
||
4 | |||
5 | |||
6 | 1255 | bneuman | void dynamos_init (void) |
7 | 1183 | deffi | { |
8 | //enable pin change interrupts 4 and 5 (correspond to DIO2 and DIO3)
|
||
9 | //to trigger on both edges
|
||
10 | cli(); |
||
11 | 1266 | kwoo | EICRB |= _BV(ISC40) | _BV(ISC50); |
12 | EIMSK |= _BV(INT4) | _BV(INT5); |
||
13 | 1183 | deffi | sei(); |
14 | |||
15 | 1251 | deffi | //enable the 5V switching regulator to power the dynamos
|
16 | 1183 | deffi | DDRB |= _BV(PB4); |
17 | PORTB &= ~_BV(PB4); |
||
18 | |||
19 | } |
||
20 | |||
21 | 1251 | deffi | void dynamos_reset (void) |
22 | 1183 | deffi | { |
23 | SYNC |
||
24 | { |
||
25 | count_l = 0;
|
||
26 | count_r = 0;
|
||
27 | } |
||
28 | } |
||
29 | |||
30 | ISR(INT4_vect) |
||
31 | { |
||
32 | uint8_t temp = PINE; |
||
33 | |||
34 | if(((temp&_BV(PE4))>>2)^(temp&_BV(PE2))) |
||
35 | 1291 | deffi | count_r--; |
36 | 1183 | deffi | else
|
37 | 1291 | deffi | count_r++; |
38 | 1183 | deffi | } |
39 | |||
40 | ISR(INT5_vect) |
||
41 | { |
||
42 | uint8_t temp = PINE; |
||
43 | |||
44 | if(((temp&_BV(PE5))>>2)^(temp&_BV(PE3))) |
||
45 | 1291 | deffi | count_l++; |
46 | 1183 | deffi | else
|
47 | 1291 | deffi | count_l--; |
48 | 1183 | deffi | } |
49 | |||
50 | |||
51 | 1291 | deffi | void dynamos_read (int16_t *left, int16_t *right)
|
52 | 1183 | deffi | { |
53 | SYNC |
||
54 | { |
||
55 | 1291 | deffi | *left= count_l; |
56 | *right = count_r; |
||
57 | 1183 | deffi | } |
58 | } |