2020-11-03 15:06:32 -08:00
|
|
|
/**
|
|
|
|
* @file idle_hardware.cpp
|
|
|
|
* @brief Idle Air Control valve hardware
|
|
|
|
*
|
|
|
|
* @date November 3, 2020
|
|
|
|
*
|
|
|
|
* This is just the hardware interface - deciding where to put the valve happens in idle_thread.cpp
|
|
|
|
*/
|
|
|
|
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
2020-11-03 15:06:32 -08:00
|
|
|
|
|
|
|
#if EFI_IDLE_CONTROL
|
|
|
|
#include "idle_hardware.h"
|
|
|
|
|
|
|
|
#include "electronic_throttle.h"
|
|
|
|
|
|
|
|
#include "dc_motors.h"
|
|
|
|
#if ! EFI_UNIT_TEST
|
|
|
|
#include "stepper.h"
|
2021-08-27 03:18:05 -07:00
|
|
|
static StepDirectionStepper iacStepperHw CCM_OPTIONAL;
|
|
|
|
static DualHBridgeStepper iacHbridgeHw CCM_OPTIONAL;
|
|
|
|
StepperMotor iacMotor CCM_OPTIONAL;
|
2020-11-03 15:06:32 -08:00
|
|
|
#endif /* EFI_UNIT_TEST */
|
|
|
|
|
|
|
|
static SimplePwm idleSolenoidOpen("idle open");
|
|
|
|
static SimplePwm idleSolenoidClose("idle close");
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void applyIACposition(percent_t position) {
|
2020-11-03 15:06:32 -08:00
|
|
|
/**
|
|
|
|
* currently idle level is an percent value (0-100 range), and PWM takes a float in the 0..1 range
|
|
|
|
* todo: unify?
|
|
|
|
*/
|
|
|
|
float duty = PERCENT_TO_DUTY(position);
|
|
|
|
|
|
|
|
if (CONFIG(useETBforIdleControl)) {
|
|
|
|
#if EFI_ELECTRONIC_THROTTLE_BODY
|
2021-11-16 01:15:29 -08:00
|
|
|
setEtbIdlePosition(position);
|
2020-11-03 15:06:32 -08:00
|
|
|
#endif // EFI_ELECTRONIC_THROTTLE_BODY
|
|
|
|
#if ! EFI_UNIT_TEST
|
|
|
|
} else if (CONFIG(useStepperIdle)) {
|
|
|
|
iacMotor.setTargetPosition(duty * engineConfiguration->idleStepperTotalSteps);
|
|
|
|
#endif /* EFI_UNIT_TEST */
|
|
|
|
} else {
|
2021-02-04 14:04:37 -08:00
|
|
|
// if not spinning or running a bench test, turn off the idle valve(s) to be quieter and save power
|
2021-10-16 21:27:12 -07:00
|
|
|
if (!engine->triggerCentral.engineMovedRecently() && engine->timeToStopIdleTest == 0) {
|
2021-02-04 14:04:37 -08:00
|
|
|
idleSolenoidOpen.setSimplePwmDutyCycle(0);
|
|
|
|
idleSolenoidClose.setSimplePwmDutyCycle(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:06:32 -08:00
|
|
|
if (!CONFIG(isDoubleSolenoidIdle)) {
|
|
|
|
idleSolenoidOpen.setSimplePwmDutyCycle(duty);
|
|
|
|
} else {
|
|
|
|
/* use 0.01..0.99 range */
|
|
|
|
float idle_range = 0.98; /* move to config? */
|
|
|
|
float idle_open, idle_close;
|
|
|
|
|
|
|
|
idle_open = 0.01 + idle_range * duty;
|
|
|
|
idle_close = 0.01 + idle_range * (1.0 - duty);
|
|
|
|
|
|
|
|
idleSolenoidOpen.setSimplePwmDutyCycle(idle_open);
|
|
|
|
idleSolenoidClose.setSimplePwmDutyCycle(idle_close);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !EFI_UNIT_TEST
|
|
|
|
|
|
|
|
bool isIdleHardwareRestartNeeded() {
|
|
|
|
return isConfigurationChanged(stepperEnablePin) ||
|
|
|
|
isConfigurationChanged(stepperEnablePinMode) ||
|
|
|
|
isConfigurationChanged(idle.stepperStepPin) ||
|
|
|
|
isConfigurationChanged(idle.solenoidFrequency) ||
|
|
|
|
isConfigurationChanged(useStepperIdle) ||
|
|
|
|
isConfigurationChanged(useETBforIdleControl) ||
|
|
|
|
isConfigurationChanged(idle.solenoidPin) ||
|
|
|
|
isConfigurationChanged(secondSolenoidPin);
|
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
bool isIdleMotorBusy() {
|
2020-11-03 15:06:32 -08:00
|
|
|
if (!CONFIG(useStepperIdle)) {
|
|
|
|
// todo: check other motor types?
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return iacMotor.isBusy();
|
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void initIdleHardware() {
|
2020-11-03 15:06:32 -08:00
|
|
|
if (CONFIG(useStepperIdle)) {
|
|
|
|
StepperHw* hw;
|
|
|
|
|
2021-09-26 15:07:09 -07:00
|
|
|
if (CONFIG(useHbridgesToDriveIdleStepper)) {
|
2021-11-16 01:15:29 -08:00
|
|
|
auto motorA = initDcMotor(engineConfiguration->stepperDcIo[0], 2, /*useTwoWires*/ true);
|
|
|
|
auto motorB = initDcMotor(engineConfiguration->stepperDcIo[1], 3, /*useTwoWires*/ true);
|
2020-11-03 15:06:32 -08:00
|
|
|
|
|
|
|
if (motorA && motorB) {
|
|
|
|
iacHbridgeHw.initialize(
|
|
|
|
motorA,
|
|
|
|
motorB,
|
|
|
|
CONFIG(idleStepperReactionTime)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
hw = &iacHbridgeHw;
|
|
|
|
} else {
|
|
|
|
iacStepperHw.initialize(
|
|
|
|
CONFIG(idle).stepperStepPin,
|
|
|
|
CONFIG(idle).stepperDirectionPin,
|
|
|
|
CONFIG(stepperDirectionPinMode),
|
|
|
|
CONFIG(idleStepperReactionTime),
|
|
|
|
CONFIG(stepperEnablePin),
|
|
|
|
CONFIG(stepperEnablePinMode)
|
|
|
|
);
|
|
|
|
|
|
|
|
hw = &iacStepperHw;
|
|
|
|
}
|
|
|
|
|
2021-04-20 11:09:41 -07:00
|
|
|
iacMotor.initialize(hw, CONFIG(idleStepperTotalSteps));
|
2021-01-08 17:01:26 -08:00
|
|
|
} else if (engineConfiguration->useETBforIdleControl || !isBrainPinValid(CONFIG(idle).solenoidPin)) {
|
2020-12-13 16:23:26 -08:00
|
|
|
// here we do nothing for ETB idle and for no idle
|
|
|
|
} else {
|
|
|
|
// we are here for single or double solenoid idle
|
|
|
|
|
2020-11-03 15:06:32 -08:00
|
|
|
/**
|
|
|
|
* Start PWM for idleValvePin
|
|
|
|
*/
|
|
|
|
// todo: even for double-solenoid mode we can probably use same single SimplePWM
|
2020-12-13 16:23:26 -08:00
|
|
|
startSimplePwm(&idleSolenoidOpen, "Idle Valve Open",
|
|
|
|
&engine->executor,
|
|
|
|
&enginePins.idleSolenoidPin,
|
2021-02-04 14:04:37 -08:00
|
|
|
CONFIG(idle).solenoidFrequency, PERCENT_TO_DUTY(CONFIG(manIdlePosition)));
|
2020-12-13 16:23:26 -08:00
|
|
|
|
|
|
|
if (CONFIG(isDoubleSolenoidIdle)) {
|
2021-01-08 17:01:26 -08:00
|
|
|
if (!isBrainPinValid(CONFIG(secondSolenoidPin))) {
|
2020-12-13 16:23:26 -08:00
|
|
|
firmwareError(OBD_PCM_Processor_Fault, "Second idle pin should be configured for double solenoid mode.");
|
|
|
|
return;
|
|
|
|
}
|
2020-11-03 15:06:32 -08:00
|
|
|
|
|
|
|
startSimplePwm(&idleSolenoidClose, "Idle Valve Close",
|
2020-11-15 21:06:11 -08:00
|
|
|
&engine->executor,
|
|
|
|
&enginePins.secondIdleSolenoidPin,
|
2021-02-04 14:04:37 -08:00
|
|
|
CONFIG(idle).solenoidFrequency, PERCENT_TO_DUTY(CONFIG(manIdlePosition)));
|
2020-11-03 15:06:32 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // EFI_IDLE_HARDWARE
|