Skip to content

Commit

Permalink
voltage compensated vvt #209
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Jul 21, 2023
1 parent 229a9d9 commit c7a7f74
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions firmware/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions firmware/controllers/actuators/vvt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

This comment has been minimized.

Copy link
@rusefillc

rusefillc Jul 23, 2023

Contributor

This comment has been minimized.

Copy link
@nmschulte

nmschulte Jul 23, 2023

Contributor

I feel like this constant has to be in other locations already as well, and the regulated voltage will depend on the board/vehicle also?

https://github.com/FOME-Tech/fome-fw/blob/master/firmware/controllers/system/dc_motor.cpp#L59

This comment has been minimized.

Copy link
@rusefillc

rusefillc Jul 23, 2023

Contributor

@nmschulte that could be "battery target" setting.

This comment has been minimized.

Copy link
@mck1117

mck1117 Jul 23, 2023

Author Collaborator

You don't want to have it follow something like that, the whole point is that it's voltage independent. If you bump your voltage target by 0.5v for whatever reason, your VVT behavior can't change.

This comment has been minimized.

Copy link
@rusefillc

rusefillc Jul 23, 2023

Contributor

14 twice is code smell. If not config then extract constant

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();
}
Expand Down

0 comments on commit c7a7f74

Please sign in to comment.