proteus-friendly VR threshold logic (#4180)
* proteus-friendly VR threshold * ddddddddddddddddddd
This commit is contained in:
parent
62698dbe99
commit
058d7dc1cc
|
@ -23,6 +23,9 @@ DDEFS += -DEFI_CAN_SERIAL=TRUE
|
||||||
# Turn off stuff proteus doesn't have/need
|
# 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
|
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
|
# This stuff doesn't work on H7 yet
|
||||||
ifneq ($(PROJECT_CPU),ARCH_STM32H7)
|
ifneq ($(PROJECT_CPU),ARCH_STM32H7)
|
||||||
DDEFS += -DSTM32_ADC_USE_ADC3=TRUE
|
DDEFS += -DSTM32_ADC_USE_ADC3=TRUE
|
||||||
|
|
|
@ -5,6 +5,11 @@
|
||||||
static OutputPin pins[VR_THRESHOLD_COUNT];
|
static OutputPin pins[VR_THRESHOLD_COUNT];
|
||||||
static SimplePwm pwms[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) {
|
static void updateVrPwm(int rpm, size_t index) {
|
||||||
auto& cfg = engineConfiguration->vrThreshold[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
|
// 0v threshold voltage = 3.3v output from mcu = 100% duty
|
||||||
// 2.5v threshold voltage = 0v output from mcu = 0% 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);
|
pwms[index].setSimplePwmDutyCycle(duty);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue