proteus-friendly VR threshold logic (#4180)

* proteus-friendly VR threshold

* ddddddddddddddddddd
This commit is contained in:
Matthew Kennedy 2022-05-17 18:35:43 -07:00 committed by GitHub
parent a90f806073
commit ba35749238
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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);
}