voltage compensated vvt #209

This commit is contained in:
Matthew Kennedy 2023-07-21 02:30:58 -07:00
parent 229a9d99dc
commit c7a7f7467c
2 changed files with 13 additions and 3 deletions

View File

@ -31,6 +31,7 @@ Release template (copy/paste this for new release):
### Added
- Log per-cylinder true ignition timing (includes trim, knock retard, etc) #76
- Add mode for CLT/IAT sensors that are installed "high side" instead of typical "low side" #116
- Automatic supply voltage compensation for VVT solenoids, giving more stable control as battery voltage changes #209
### Fixed
- Improved bench test resolution (more usable for testing injectors, dwell, etc)

View File

@ -106,13 +106,22 @@ void VvtController::setOutput(expected<percent_t> outputValue) {
&& engine->rpmCalculator.getSecondsSinceEngineStart(getTimeNowNt()) > engineConfiguration->vvtActivationDelayMs / MS_PER_SECOND
;
vvtOutput = outputValue.value_or(0);
if (outputValue && enabled) {
m_pwm->setSimplePwmDutyCycle(PERCENT_TO_DUTY(outputValue.Value));
float vvtPct = outputValue.Value;
// Compensate for battery voltage so that the % output is actually % solenoid current normalized
// to a 14v supply (boost duty when battery is low, etc)
float voltageRatio = 14 / Sensor::get(SensorType::BatteryVoltage).value_or(14);
vvtPct *= voltageRatio;
vvtOutput = vvtPct;
m_pwm->setSimplePwmDutyCycle(PERCENT_TO_DUTY(vvtPct));
} else {
m_pwm->setSimplePwmDutyCycle(0);
vvtOutput = 0;
// we need to avoid accumulating iTerm while engine is not running
m_pid.reset();
}