root / toolbox / current.c @ 036b4f9a
History | View | Annotate | Download (600 Bytes)
1 | 10936c07 | Tom Mullins | #include "current.h" |
---|---|---|---|
2 | #include <avr/io.h> |
||
3 | |||
4 | void current_init() {
|
||
5 | /*
|
||
6 | * REFS = 0, Vcc reference (set to 2 for internal 1.1V reference)
|
||
7 | * MUX = 8, PB3(ADC8)
|
||
8 | */
|
||
9 | ADMUX = _BV(MUX3); |
||
10 | /* TODO reduce power consumption with DIDR* */
|
||
11 | /*
|
||
12 | * ADLAR = 0, right adjust result
|
||
13 | * ADTS = 0, free running mode
|
||
14 | */
|
||
15 | ADCSRB = 0;
|
||
16 | /*
|
||
17 | * ADEN = 1, enable
|
||
18 | * ADSC = 1, start now
|
||
19 | * ADATE = 1, auto trigger
|
||
20 | * ADIE = 0, disable interrupt
|
||
21 | * ADPS = 3, prescale clock by 8
|
||
22 | */
|
||
23 | ADCSRA |= _BV(ADEN) | _BV(ADSC) | _BV(ADATE) | _BV(ADPS1) | _BV(ADPS0); |
||
24 | } |
||
25 | |||
26 | int current_read() {
|
||
27 | return ADC;
|
||
28 | } |