Support non-uniform dividers on ADC inputs (#4938)
* adc: support per-channel dividers * S105: non-uniform analog dividers * adc: default weak getAnalogInputDividerCoefficient() implementation * adc: fix emulator compilation
This commit is contained in:
parent
d2ee2cbff9
commit
e086176fc1
|
@ -13,4 +13,4 @@
|
|||
|
||||
#define getAdcValue(channel) getMcp3208adc(channel)
|
||||
#define adcToVoltsDivided(adc) (5.0f / 4095 * (adc))
|
||||
#define getVoltageDivided(msg, channel) (isAdcChannelValid(channel) ? adcToVoltsDivided(getAdcValue(msg, channel)) : 66.66)
|
||||
#define getVoltageDivided(msg, channel) (isAdcChannelValid(channel) ? adcToVoltsDivided(getAdcValue(msg, channel), channel) : 66.66)
|
||||
|
|
|
@ -21,8 +21,11 @@
|
|||
|
||||
#include "pch.h"
|
||||
|
||||
#if HAL_USE_ADC
|
||||
float __attribute__((weak)) getAnalogInputDividerCoefficient(adc_channel_e) {
|
||||
return engineConfiguration->analogInputDividerCoefficient;
|
||||
}
|
||||
|
||||
#if HAL_USE_ADC
|
||||
|
||||
#include "adc_subscription.h"
|
||||
#include "AdcConfiguration.h"
|
||||
|
@ -42,7 +45,7 @@ static adc_channel_mode_e adcHwChannelEnabled[HW_MAX_ADC_INDEX];
|
|||
|
||||
// Board voltage, with divider coefficient accounted for
|
||||
float getVoltageDivided(const char *msg, adc_channel_e hwChannel) {
|
||||
return getVoltage(msg, hwChannel) * engineConfiguration->analogInputDividerCoefficient;
|
||||
return getVoltage(msg, hwChannel) * getAnalogInputDividerCoefficient(hwChannel);
|
||||
}
|
||||
|
||||
// voltage in MCU universe, from zero to VDD
|
||||
|
@ -295,7 +298,7 @@ adc_channel_e AdcDevice::getAdcHardwareIndexByInternalIndex(int index) const {
|
|||
|
||||
static void printAdcValue(int channel) {
|
||||
int value = getAdcValue("print", (adc_channel_e)channel);
|
||||
float volts = adcToVoltsDivided(value);
|
||||
float volts = adcToVoltsDivided(value, (adc_channel_e)channel);
|
||||
efiPrintf("adc voltage : %.2f", volts);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#define SLOW_ADC_RATE 500
|
||||
#endif
|
||||
|
||||
float getAnalogInputDividerCoefficient(adc_channel_e);
|
||||
|
||||
static inline bool isAdcChannelValid(adc_channel_e hwChannel) {
|
||||
if (hwChannel <= EFI_ADC_NONE) {
|
||||
return false;
|
||||
|
@ -66,7 +68,7 @@ void removeChannel(const char *name, adc_channel_e setting);
|
|||
|
||||
#define getAdcValue(msg, hwChannel) getInternalAdcValue(msg, hwChannel)
|
||||
|
||||
#define adcToVoltsDivided(adc) (adcToVolts(adc) * engineConfiguration->analogInputDividerCoefficient)
|
||||
#define adcToVoltsDivided(adc, hwChannel) (adcToVolts(adc) * getAnalogInputDividerCoefficient(hwChannel))
|
||||
|
||||
#if !defined(GPT_FREQ_FAST) || !defined(GPT_PERIOD_FAST)
|
||||
/**
|
||||
|
|
|
@ -86,9 +86,9 @@ TODO: this code is similar to initIfValid, what is the plan? shall we extract he
|
|||
efiSetPadMode(name, pin, PAL_MODE_INPUT_ANALOG);
|
||||
}
|
||||
|
||||
// if 0, default to the board's divider coefficient
|
||||
// if 0, default to the board's divider coefficient for given channel
|
||||
if (voltsPerAdcVolt == 0) {
|
||||
voltsPerAdcVolt = engineConfiguration->analogInputDividerCoefficient;
|
||||
voltsPerAdcVolt = getAnalogInputDividerCoefficient(channel);
|
||||
}
|
||||
#endif /* EFI_PROD_CODE */
|
||||
// Populate the entry
|
||||
|
|
|
@ -185,11 +185,11 @@ void onFastAdcComplete(adcsample_t*) {
|
|||
#endif /* EFI_SENSOR_CHART */
|
||||
|
||||
#if EFI_MAP_AVERAGING
|
||||
mapAveragingAdcCallback(adcToVoltsDivided(getFastAdc(fastMapSampleIndex)));
|
||||
mapAveragingAdcCallback(adcToVoltsDivided(getFastAdc(fastMapSampleIndex), engineConfiguration->map.sensor.hwChannel));
|
||||
#endif /* EFI_MAP_AVERAGING */
|
||||
#if EFI_HIP_9011
|
||||
if (engineConfiguration->isHip9011Enabled) {
|
||||
hipAdcCallback(adcToVoltsDivided(getFastAdc(hipSampleIndex)));
|
||||
hipAdcCallback(adcToVoltsDivided(getFastAdc(hipSampleIndex), engineConfiguration->hipOutputChannel));
|
||||
}
|
||||
#endif /* EFI_HIP_9011 */
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue