| 1 |
#include "Types.h" |
| 2 |
#include "AdcTemperatureSensor.h" |
| 3 |
|
| 4 |
static inline uint32 ConvertAdcCountsToPicovolts(uint32 counts); |
| 5 |
static inline uint16 ConvertPicovoltsToMillivolts(uint32 picovolts); |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
void Adc_StartTemperatureSensorConversion(void) |
| 12 |
{ |
| 13 |
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START; |
| 14 |
} |
| 15 |
|
| 16 |
bool Adc_TemperatureSensorSampleReady(void) |
| 17 |
{ |
| 18 |
return ((AT91C_BASE_ADC->ADC_SR & AT91C_ADC_EOC4) == AT91C_ADC_EOC4); |
| 19 |
} |
| 20 |
|
| 21 |
uint16 Adc_ReadTemperatureSensor(void) |
| 22 |
{ |
| 23 |
uint32 picovolts = ConvertAdcCountsToPicovolts(AT91C_BASE_ADC->ADC_CDR4); |
| 24 |
return ConvertPicovoltsToMillivolts(picovolts); |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
static inline uint32 ConvertAdcCountsToPicovolts(uint32 counts) |
| 32 |
{ |
| 33 |
|
| 34 |
uint32 picovoltsPerAdcCount = 2929688; |
| 35 |
|
| 36 |
|
| 37 |
return counts * picovoltsPerAdcCount; |
| 38 |
} |
| 39 |
|
| 40 |
static inline uint16 ConvertPicovoltsToMillivolts(uint32 picovolts) |
| 41 |
{ |
| 42 |
const uint32 halfMillivoltInPicovolts = 500000; |
| 43 |
const uint32 picovoltsPerMillivolt = 1000000; |
| 44 |
|
| 45 |
|
| 46 |
picovolts += halfMillivoltInPicovolts; |
| 47 |
|
| 48 |
|
| 49 |
return (uint16)(picovolts / picovoltsPerMillivolt); |
| 50 |
} |
| 51 |
|