From a7cafdf9890d10b15ca2a66394ebb42f5ec6916c Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Wed, 30 Jun 2021 12:09:11 +0800 Subject: [PATCH] Use temperature formula from reference manual code example. --- adc.c | 8 ++++---- adcmain.c | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/adc.c b/adc.c index cdba1be..c34cfc4 100644 --- a/adc.c +++ b/adc.c @@ -1,5 +1,5 @@ /* adc.c -- system layer -** Copyright (c) 2020 Renaud Fivet +** Copyright (c) 2020-2021 Renaud Fivet ** ** ADC for temperature sensor and Vrefint ** gpioa low level API and usleep() @@ -118,7 +118,7 @@ /** SYSTEM MEMORY *************************************************************/ /* STM32F030 calibration addresses (at 3.3V and 30C) */ -#define TS_CAL ((unsigned short *) 0x1FFFF7B8) +#define TS_CAL1 ((unsigned short *) 0x1FFFF7B8) #define VREFINT_CAL ((unsigned short *) 0x1FFFF7BA) @@ -298,7 +298,7 @@ void adc_vnt( vnt_cmd_t cmd, short *ptrV, short *ptrC) { if( cmd <= VNT_CAL) { /* Calibration Values */ *ptrV = *VREFINT_CAL ; - *ptrC = *TS_CAL ; + *ptrC = *TS_CAL1 ; return ; } @@ -307,8 +307,8 @@ void adc_vnt( vnt_cmd_t cmd, short *ptrV, short *ptrC) { *ptrV = adc_convert() ; if( cmd == VNT_VNC) { + *ptrC = 300 + (*TS_CAL1 - *ptrC * *VREFINT_CAL / *ptrV) * 10000 / 5336 ; *ptrV = 330 * *VREFINT_CAL / *ptrV ; - *ptrC = 850 + (1500 - *ptrC) * 10 / 4 ; } } diff --git a/adcmain.c b/adcmain.c index 9b90d05..cc5f425 100644 --- a/adcmain.c +++ b/adcmain.c @@ -1,5 +1,5 @@ /* adcmain.c -- ADC reading of reference voltage and temperature sensor */ -/* Copyright (c) 2020 Renaud Fivet */ +/* Copyright (c) 2020-2021 Renaud Fivet */ #include #include "system.h" @@ -26,8 +26,9 @@ int main( void) { #ifdef RAW adc_vnt( VNT_RAW, &Vsample, &Csample) ; printf( "%i, %i, %i, %i, ", calV, Vsample, calC, Csample) ; + Csample = 300 + (calC - (int) Csample * calV / Vsample) + * 10000 / 5336 ; Vsample = 330 * calV / Vsample ; - Csample = 850 + (1500 - (int) Csample) * 10 / 4 ; #else adc_vnt( VNT_VNC, &Vsample, &Csample) ; #endif