auto-sync

This commit is contained in:
rusEfi 2016-02-25 17:01:37 -05:00
parent 1f3604c1a0
commit affb865517
1 changed files with 33 additions and 5 deletions

View File

@ -1,6 +1,6 @@
/** /**
* @file alternatorController.cpp * @file alternatorController.cpp
* @brief alternator controller - turn alternator off if you do not really need it * @brief alternator controller - some newer vehicles control alternator with ECU
* *
* @date Apr 6, 2014 * @date Apr 6, 2014
* @author Dmitry Sidin * @author Dmitry Sidin
@ -27,6 +27,8 @@ static Logging *logger;
#define ALTERNATOR_VALVE_PWM_FREQUENCY 300 #define ALTERNATOR_VALVE_PWM_FREQUENCY 300
extern pin_output_mode_e DEFAULT_OUTPUT;
static SimplePwm alternatorControl; static SimplePwm alternatorControl;
static OutputPin alternatorPin; static OutputPin alternatorPin;
static pid_s *altPidS = &persistentState.persistentConfiguration.engineConfiguration.alternatorControl; static pid_s *altPidS = &persistentState.persistentConfiguration.engineConfiguration.alternatorControl;
@ -41,6 +43,9 @@ static LocalVersionHolder parametersVersion;
extern TunerStudioOutputChannels tsOutputChannels; extern TunerStudioOutputChannels tsOutputChannels;
#endif #endif
static bool plainOnOffControlEnabled = false;
static bool currentPlainOnOffState = false;
static msg_t AltCtrlThread(int param) { static msg_t AltCtrlThread(int param) {
UNUSED(param); UNUSED(param);
chRegSetThreadName("AlternatorController"); chRegSetThreadName("AlternatorController");
@ -63,7 +68,24 @@ static msg_t AltCtrlThread(int param) {
continue; continue;
} }
currentAltDuty = altPid.getValue(engineConfiguration->targetVBatt, getVBatt(PASS_ENGINE_PARAMETER_F), 1); float vBatt = getVBatt(PASS_ENGINE_PARAMETER_F);
float targetVoltage = engineConfiguration->targetVBatt;
if (plainOnOffControlEnabled) {
float h = 0.1;
bool newState = (vBatt < targetVoltage - h) || (currentPlainOnOffState && vBatt < targetVoltage);
alternatorPin.setValue(newState);
currentPlainOnOffState = newState;
if (engineConfiguration->debugMode == ALTERNATOR) {
tsOutputChannels.debugIntField1 = newState;
}
continue;
}
currentAltDuty = altPid.getValue(targetVoltage, vBatt, 1);
if (boardConfiguration->isVerboseAlternator) { if (boardConfiguration->isVerboseAlternator) {
scheduleMsg(logger, "alt duty: %f/vbatt=%f/p=%f/i=%f/d=%f int=%f", currentAltDuty, getVBatt(PASS_ENGINE_PARAMETER_F), scheduleMsg(logger, "alt duty: %f/vbatt=%f/p=%f/i=%f/d=%f int=%f", currentAltDuty, getVBatt(PASS_ENGINE_PARAMETER_F),
altPid.getP(), altPid.getI(), altPid.getD(), altPid.getIntegration()); altPid.getP(), altPid.getI(), altPid.getD(), altPid.getIntegration());
@ -128,9 +150,15 @@ void initAlternatorCtrl(Logging *sharedLogger) {
if (boardConfiguration->alternatorControlPin == GPIO_UNASSIGNED) if (boardConfiguration->alternatorControlPin == GPIO_UNASSIGNED)
return; return;
if (plainOnOffControlEnabled) {
outputPinRegisterExt2("on/off alternator", &alternatorPin, boardConfiguration->alternatorControlPin,
&DEFAULT_OUTPUT);
} else {
startSimplePwmExt(&alternatorControl, "Alternator control", boardConfiguration->alternatorControlPin, startSimplePwmExt(&alternatorControl, "Alternator control", boardConfiguration->alternatorControlPin,
&alternatorPin, &alternatorPin,
ALTERNATOR_VALVE_PWM_FREQUENCY, 0.1, applyAlternatorPinState); ALTERNATOR_VALVE_PWM_FREQUENCY, 0.1, applyAlternatorPinState);
}
chThdCreateStatic(alternatorControlThreadStack, sizeof(alternatorControlThreadStack), LOWPRIO, chThdCreateStatic(alternatorControlThreadStack, sizeof(alternatorControlThreadStack), LOWPRIO,
(tfunc_t) AltCtrlThread, NULL); (tfunc_t) AltCtrlThread, NULL);
} }