From: asterix Date: Tue, 22 Mar 2011 13:09:40 +0000 (+0000) Subject: Add some utility to read the temperature sensor on chip. X-Git-Tag: 2.7.0~176 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=873b979d4a79fa940931abf55f732d20aec36704;p=bertos.git Add some utility to read the temperature sensor on chip. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4790 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/boards/sam3x-ek/hw/hw_adc.h b/boards/sam3x-ek/hw/hw_adc.h new file mode 100644 index 00000000..4f0bc243 --- /dev/null +++ b/boards/sam3x-ek/hw/hw_adc.h @@ -0,0 +1,65 @@ +/** + * \file + * + * + * \brief Some ADC utilis. + * + * \author Daniele Basile + */ + +#ifndef HW_ADC_H +#define HW_ADC_H + +#include + + +/* + * Enable temperature sensor + */ +INLINE void hw_enableTempRead(void) +{ + + ADC_ACR = BV(ADC_TSON); +} + + +/* + * The VT voltage equals 0.8V at 27°C with a +/-15% accuracy. + * The VT output voltage linearly varies with a temperature slope dVT/dT = 2.65. + * So the formula is: x = (vol - 800) / 2.65 + 27. + */ +INLINE uint16_t hw_convertToDegree(uint16_t raw_temp) +{ + raw_temp = raw_temp * 3300 * 10 / 4096; + return ((raw_temp - 8000) * 100 / 265 + 270); +} + +#endif /* HW_ADC_H */