Rev 853 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 853 | Rev 913 | ||
|---|---|---|---|
| Line 8... | Line 8... | ||
| 8 | 8 | ||
| 9 | #include <config.h> |
9 | #include <config.h> |
| 10 | #include "adc.h" |
10 | #include "adc.h" |
| 11 | 11 | ||
| 12 | #define BV(x) (1<<(x)) |
12 | #define BV(x) (1<<(x)) |
| - | 13 | ||
| - | 14 | // Find a suitable prescaler to get between 75KHz and 150kHz ADC clock |
|
| - | 15 | #ifndef ADC_PRESCALER |
|
| - | 16 | #if (F_CPU < 300000) |
|
| - | 17 | #define ADC_PRESCALER 1 // F_CPU/2 |
|
| - | 18 | #elif (F_CPU < 600000) |
|
| - | 19 | #define ADC_PRESCALER 2 // F_CPU/4 |
|
| - | 20 | #elif (F_CPU < 1200000) |
|
| - | 21 | #define ADC_PRESCALER 3 // F_CPU/8 |
|
| - | 22 | #elif (F_CPU < 2400000) |
|
| - | 23 | #define ADC_PRESCALER 4 // F_CPU/16 |
|
| - | 24 | #elif (F_CPU < 4800000) |
|
| - | 25 | #define ADC_PRESCALER 5 // F_CPU/32 |
|
| - | 26 | #elif (F_CPU < 9600000) |
|
| - | 27 | #define ADC_PRESCALER 6 // F_CPU/64 |
|
| - | 28 | #else |
|
| - | 29 | #define ADC_PRESCALER 7 // F_CPU/128 |
|
| - | 30 | #endif |
|
| - | 31 | #endif |
|
| 13 | 32 | ||
| 14 | /*---------------------------------------------- |
33 | /*---------------------------------------------- |
| 15 | * Functions |
34 | * Functions |
| 16 | * --------------------------------------------*/ |
35 | * --------------------------------------------*/ |
| 17 | 36 | ||
| Line 26... | Line 45... | ||
| 26 | /* Right adjust the result */ |
45 | /* Right adjust the result */ |
| 27 | ADMUX &= ~(1<<ADLAR); |
46 | ADMUX &= ~(1<<ADLAR); |
| 28 | 47 | ||
| 29 | /* Wake up ADC and enable it */ |
48 | /* Wake up ADC and enable it */ |
| 30 | PRR &= ~(1<<PRADC); |
49 | PRR &= ~(1<<PRADC); |
| 31 | ADCSRA |
50 | ADCSRA = (1<<ADEN) | ((ADC_PRESCALER&7)<<ADPS0); |
| 32 | 51 | ||
| 33 | /* Make sure that the next ADC_Get will do an empty measurement first by setting the channel to an impossible value */ |
52 | /* Make sure that the next ADC_Get will do an empty measurement first by setting the channel to an impossible value */ |
| 34 | currentChannel = 10; |
53 | currentChannel = 10; |
| 35 | 54 | ||
| 36 | return 0; |
55 | return 0; |