adc: try to clean naming mess: getVoltageDivided() rename to adcGetScaledVoltage()

This commit is contained in:
Andrey Gusakov 2024-12-09 14:13:22 +03:00 committed by rusefillc
parent cbe59c90c9
commit 0ed513f3f3
8 changed files with 18 additions and 14 deletions

View File

@ -501,12 +501,12 @@ static void updateRawSensors() {
for (int i = 0; i < LUA_ANALOG_INPUT_COUNT; i++) { for (int i = 0; i < LUA_ANALOG_INPUT_COUNT; i++) {
adc_channel_e channel = engineConfiguration->auxAnalogInputs[i]; adc_channel_e channel = engineConfiguration->auxAnalogInputs[i];
if (isAdcChannelValid(channel)) { if (isAdcChannelValid(channel)) {
engine->outputChannels.rawAnalogInput[i] = getVoltageDivided("raw aux", channel); engine->outputChannels.rawAnalogInput[i] = adcGetScaledVoltage("raw aux", channel);
} }
} }
// TODO: transition AFR to new sensor model // TODO: transition AFR to new sensor model
engine->outputChannels.rawAfr = (engineConfiguration->afr.hwChannel == EFI_ADC_NONE) ? 0 : getVoltageDivided("ego", engineConfiguration->afr.hwChannel); engine->outputChannels.rawAfr = (engineConfiguration->afr.hwChannel == EFI_ADC_NONE) ? 0 : adcGetScaledVoltage("ego", engineConfiguration->afr.hwChannel);
} }
static void updatePressures() { static void updatePressures() {
engine->outputChannels.baroPressure = Sensor::getOrZero(SensorType::BarometricPressure); engine->outputChannels.baroPressure = Sensor::getOrZero(SensorType::BarometricPressure);

View File

@ -30,7 +30,7 @@ float getAfr(SensorType type) {
return 0; return 0;
} }
float volts = getVoltageDivided("ego", type == SensorType::Lambda1 ? sensor->hwChannel : sensor->hwChannel2); float volts = adcGetScaledVoltage("ego", type == SensorType::Lambda1 ? sensor->hwChannel : sensor->hwChannel2);
return interpolateMsg("AFR", sensor->v1, sensor->value1, sensor->v2, sensor->value2, volts) return interpolateMsg("AFR", sensor->v1, sensor->value1, sensor->v2, sensor->value2, volts)
+ engineConfiguration->egoValueShift; + engineConfiguration->egoValueShift;

View File

@ -11,6 +11,8 @@
#include "mcp3208.h" #include "mcp3208.h"
/* 12 bits, 5V reference */
#define adcRawToScaledVoltage(adc) (5.0f / 4095 * (adc))
#define adcGetRawValue(channel) getMcp3208adc(channel) #define adcGetRawValue(channel) getMcp3208adc(channel)
#define adcToVoltsDivided(adc) (5.0f / 4095 * (adc)) #define adcGetScaledVoltage(msg, channel) (isAdcChannelValid(channel) ? adcToVoltsDivided(adcGetRawValue(msg, channel), channel) : 66.66)
#define getVoltageDivided(msg, channel) (isAdcChannelValid(channel) ? adcToVoltsDivided(adcGetRawValue(msg, channel), channel) : 66.66)

View File

@ -75,12 +75,12 @@ static void printAdcChannedReport(const char *prefix, int internalIndex, adc_cha
int pin = getAdcChannelPin(hwChannel); int pin = getAdcChannelPin(hwChannel);
int adcValue = adcGetRawValue("print", hwChannel); int adcValue = adcGetRawValue("print", hwChannel);
float volts = adcGetRawVoltage("print", hwChannel); float volts = adcGetRawVoltage("print", hwChannel);
float voltsDivided = getVoltageDivided("print", hwChannel); float voltsInput = adcGetScaledVoltage("print", hwChannel);
/* Human index starts from 1 */ /* Human index starts from 1 */
efiPrintf(" %s ch[%2d] @ %s%d ADC%d 12bit=%4d %.3fV (input %.3fV)", efiPrintf(" %s ch[%2d] @ %s%d ADC%d 12bit=%4d %.3fV (input %.3fV)",
prefix, internalIndex, portname(port), pin, prefix, internalIndex, portname(port), pin,
/* TODO: */ hwChannel - EFI_ADC_0 + 1, /* TODO: */ hwChannel - EFI_ADC_0 + 1,
adcValue, volts, voltsDivided); adcValue, volts, voltsInput);
} }
} }
@ -240,7 +240,8 @@ __attribute__((weak)) float adcGetRawVoltage(const char*, adc_channel_e) {
return 0; return 0;
} }
__attribute__((weak)) float getVoltageDivided(const char*, adc_channel_e) { // voltage in ECU universe, with all input dividers and OpAmps gains taken into account, voltage at ECU connector pin
__attribute__((weak)) float adcGetScaledVoltage(const char*, adc_channel_e) {
return 0; return 0;
} }

View File

@ -34,8 +34,8 @@ float adcGetRawVoltage(const char *msg, adc_channel_e hwChannel) {
return adcToRawVolts(adcGetRawValue(msg, hwChannel)); return adcToRawVolts(adcGetRawValue(msg, hwChannel));
} }
// Board voltage, with divider coefficient accounted for // voltage in ECU universe, with all input dividers and OpAmps gains taken into account, voltage at ECU connector pin
float getVoltageDivided(const char *msg, adc_channel_e hwChannel) { float adcGetScaledVoltage(const char *msg, adc_channel_e hwChannel) {
return adcGetRawVoltage(msg, hwChannel) * getAnalogInputDividerCoefficient(hwChannel); return adcGetRawVoltage(msg, hwChannel) * getAnalogInputDividerCoefficient(hwChannel);
} }

View File

@ -24,5 +24,6 @@
// voltage in MCU universe, from zero to Vref // voltage in MCU universe, from zero to Vref
float adcGetRawVoltage(const char *msg, adc_channel_e channel); float adcGetRawVoltage(const char *msg, adc_channel_e channel);
float getVoltageDivided(const char *msg, adc_channel_e channel); // voltage in ECU universe, with all input dividers and OpAmps gains taken into account, voltage at ECU connector pin
float adcGetScaledVoltage(const char *msg, adc_channel_e channel);

View File

@ -20,7 +20,7 @@ float adcGetRawVoltage(const char *msg, adc_channel_e hwChannel) {
return adcToRawVolts(adcGetRawValue(msg, hwChannel)); return adcToRawVolts(adcGetRawValue(msg, hwChannel));
} }
// Board voltage, with divider coefficient accounted for // voltage in ECU universe, with all input dividers and OpAmps gains taken into account, voltage at ECU connector pin
float getVoltageDivided(const char *msg, adc_channel_e hwChannel) { float adcGetScaledVoltage(const char *msg, adc_channel_e hwChannel) {
return adcGetRawVoltage(msg, hwChannel) * engineConfiguration->analogInputDividerCoefficient; return adcGetRawVoltage(msg, hwChannel) * engineConfiguration->analogInputDividerCoefficient;
} }

View File

@ -17,6 +17,6 @@ float adcGetRawVoltage(const char *msg, adc_channel_e hwChannel) {
return 0; return 0;
} }
float getVoltageDivided(const char *msg, adc_channel_e hwChannel) { float adcGetScaledVoltage(const char *msg, adc_channel_e hwChannel) {
return 0; return 0;
} }