diff --git a/firmware/config/boards/proteus/board.mk b/firmware/config/boards/proteus/board.mk index 8ca761254e..b04872bd2a 100644 --- a/firmware/config/boards/proteus/board.mk +++ b/firmware/config/boards/proteus/board.mk @@ -23,6 +23,9 @@ DDEFS += -DEFI_CAN_SERIAL=TRUE # Turn off stuff proteus doesn't have/need DDEFS += -DEFI_CJ125=FALSE -DEFI_MAX_31855=FALSE -DBOARD_L9779_COUNT=0 -DBOARD_TLE8888_COUNT=0 -DEFI_HD44780_LCD=FALSE -DEFI_LCD=FALSE +# Any Proteus-based adapter boards with discrete-VR decoder are controlled via a 5v ignition output +DDEFS += -DVR_SUPPLY_VOLTAGE=5 + # This stuff doesn't work on H7 yet ifneq ($(PROJECT_CPU),ARCH_STM32H7) DDEFS += -DSTM32_ADC_USE_ADC3=TRUE diff --git a/firmware/controllers/sensors/vr_pwm.cpp b/firmware/controllers/sensors/vr_pwm.cpp index f3996ea12f..52ddb362c9 100644 --- a/firmware/controllers/sensors/vr_pwm.cpp +++ b/firmware/controllers/sensors/vr_pwm.cpp @@ -5,6 +5,11 @@ static OutputPin pins[VR_THRESHOLD_COUNT]; static SimplePwm pwms[VR_THRESHOLD_COUNT]; +// Default to 3.3v if not defined, most boards wire the VR threshold input directly to an MCU pin. +#ifndef VR_SUPPLY_VOLTAGE +#define VR_SUPPLY_VOLTAGE 3.3f +#endif + static void updateVrPwm(int rpm, size_t index) { auto& cfg = engineConfiguration->vrThreshold[index]; @@ -16,7 +21,9 @@ static void updateVrPwm(int rpm, size_t index) { // 0v threshold voltage = 3.3v output from mcu = 100% duty // 2.5v threshold voltage = 0v output from mcu = 0% duty - float duty = interpolateClamped(0, 1, 2.5f, 0, thresholdVoltage); + float thresholdInputVoltage = interpolateClamped(0, 3.3f, 2.5f, 0, thresholdVoltage); + + float duty = thresholdInputVoltage / VR_SUPPLY_VOLTAGE; pwms[index].setSimplePwmDutyCycle(duty); }