From a4c41f427c686472d14cb2b37364399643a5dd08 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Tue, 18 Jun 2019 00:10:36 +1200 Subject: [PATCH] Avoid recalculation of ADC vrefMv, add vrefMv to ADC_INTERNAL debug mode. (#8427) Avoid recalculation of ADC vrefMv, add vrefMv to ADC_INTERNAL debug mode. --- src/main/sensors/adcinternal.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/sensors/adcinternal.c b/src/main/sensors/adcinternal.c index 1ed2f345bfb..5e5904e90d4 100644 --- a/src/main/sensors/adcinternal.c +++ b/src/main/sensors/adcinternal.c @@ -57,13 +57,14 @@ static uint16_t adcTempsensorValues[8]; movingAverageStateUint16_t adcTempsensorAverageState = { 0, adcTempsensorValues, 8, 0 } ; static int16_t coreTemperature; +static uint16_t vrefMv; uint16_t getVrefMv(void) { #ifdef ADC_VOLTAGE_REFERENCE_MV return ADC_VOLTAGE_REFERENCE_MV; #else - return 3300 * adcVrefintValue / adcVREFINTCAL; + return vrefMv; #endif } @@ -86,12 +87,15 @@ void adcInternalProcess(timeUs_t currentTimeUs) adcVrefintValue = updateMovingAverageUint16(&adcVrefintAverageState, vrefintSample); adcTempsensorValue = updateMovingAverageUint16(&adcTempsensorAverageState, tempsensorSample); - int32_t adcTempsensorAdjusted = (int32_t)adcTempsensorValue * 3300 / getVrefMv(); + vrefMv = 3300 * adcVrefintValue / adcVREFINTCAL; + + int32_t adcTempsensorAdjusted = (int32_t)(adcTempsensorValue * 3300) / vrefMv; coreTemperature = ((adcTempsensorAdjusted - adcTSCAL1) * adcTSSlopeK + 30 * 1000 + 500) / 1000; DEBUG_SET(DEBUG_ADC_INTERNAL, 0, coreTemperature); DEBUG_SET(DEBUG_ADC_INTERNAL, 1, vrefintSample); DEBUG_SET(DEBUG_ADC_INTERNAL, 2, tempsensorSample); + DEBUG_SET(DEBUG_ADC_INTERNAL, 3, vrefMv); adcInternalStartConversion(); // Start next conversion }