From aca6bbcc7cc5625d1bae4b059d068840cfb84768 Mon Sep 17 00:00:00 2001 From: asterix Date: Tue, 29 Jun 2010 09:25:19 +0000 Subject: [PATCH] Implement the temperature computation in fixed point. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3966 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/cortex-m3/io/stm32_adc.h | 10 +++++----- boards/stm32-p103/hw/hw_adc.h | 12 +++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/bertos/cpu/cortex-m3/io/stm32_adc.h b/bertos/cpu/cortex-m3/io/stm32_adc.h index 09bb0748..a3d4d2ed 100644 --- a/bertos/cpu/cortex-m3/io/stm32_adc.h +++ b/bertos/cpu/cortex-m3/io/stm32_adc.h @@ -277,11 +277,11 @@ /* ADC defines for SMT32F103Bxx */ -#define ADC_TEMP_V25 4.3 -#define ADC_TEMP_SLOPE 1.43 -#define ADC_TEMP_CONST 25 -#define ADC_TEMP_CH 16 -#define ADC_VREFINT_CH 17 +#define ADC_TEMP_V25 4300 // uV / C +#define ADC_TEMP_SLOPE 1430 // mV +#define ADC_TEMP_CONST 25000 +#define ADC_TEMP_CH 16 +#define ADC_VREFINT_CH 17 struct stm32_adc { diff --git a/boards/stm32-p103/hw/hw_adc.h b/boards/stm32-p103/hw/hw_adc.h index c2c321f1..0313b2fc 100644 --- a/boards/stm32-p103/hw/hw_adc.h +++ b/boards/stm32-p103/hw/hw_adc.h @@ -43,7 +43,7 @@ #include /* - * Return the Vrefint voltage in mV + * Return the Vrefint voltage in mV. */ INLINE uint16_t hw_readVrefint(void) { @@ -51,12 +51,14 @@ INLINE uint16_t hw_readVrefint(void) } /* - * Return the cpu core temperature in degrees. + * Return the cpu core temperature in degrees * 100. */ -INLINE float hw_readIntTemp(void) +INLINE uint16_t hw_readIntTemp(void) { - float vsens = ADC_RANGECONV(adc_read(ADC_TEMP_CH), 0, 3.3); - return (float)(((ADC_TEMP_V25 - vsens) / ADC_TEMP_SLOPE) + ADC_TEMP_CONST); + uint16_t vsens = ADC_RANGECONV(adc_read(ADC_TEMP_CH), 0, 3300); + + uint16_t temp = (((ADC_TEMP_V25 - vsens) * 1000)/ ADC_TEMP_SLOPE) + ADC_TEMP_CONST; + return (temp / 10); } #endif /* HW_ADC_H */ -- 2.25.1