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