Skip to content

Commit

Permalink
Avoid recalculation of ADC vrefMv, add vrefMv to ADC_INTERNAL debug m…
Browse files Browse the repository at this point in the history
…ode. (betaflight#8427)

Avoid recalculation of ADC vrefMv, add vrefMv to ADC_INTERNAL debug mode.
  • Loading branch information
mikeller committed Jul 24, 2019
1 parent 119a65b commit a4c41f4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/sensors/adcinternal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down

0 comments on commit a4c41f4

Please sign in to comment.