2017-11-25 22:17:37 -08:00
|
|
|
/*
|
2020-11-05 13:34:25 -08:00
|
|
|
* @file aux_valves.cpp
|
2017-11-25 22:17:37 -08:00
|
|
|
*
|
2017-11-27 18:49:58 -08:00
|
|
|
*
|
|
|
|
* Here we have two auxilary digital on/off outputs which would open once per each 360 degrees of engine crank revolution.
|
|
|
|
* The second valve is 180 degrees after the first one.
|
|
|
|
*
|
2021-11-04 20:19:44 -07:00
|
|
|
* Valve open and close angles are taken from scriptCurve1 and scriptCurve2 tables respectively, the position depend on TPS input.
|
2017-11-27 18:49:58 -08:00
|
|
|
*
|
|
|
|
* https://github.com/rusefi/rusefi/issues/490
|
|
|
|
*
|
2017-11-25 22:17:37 -08:00
|
|
|
* @date Nov 25, 2017
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2017-11-25 22:17:37 -08:00
|
|
|
*/
|
|
|
|
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2017-11-25 22:17:37 -08:00
|
|
|
#include "aux_valves.h"
|
2017-11-26 19:30:37 -08:00
|
|
|
#include "trigger_central.h"
|
2019-12-02 21:29:12 -08:00
|
|
|
#include "spark_logic.h"
|
2017-11-26 19:30:37 -08:00
|
|
|
|
2020-11-05 15:10:44 -08:00
|
|
|
static void plainPinTurnOff(NamedOutputPin *output) {
|
|
|
|
output->setLow();
|
|
|
|
}
|
|
|
|
|
2020-11-06 18:24:58 -08:00
|
|
|
|
|
|
|
static void scheduleOpen(AuxActor *current) {
|
2021-11-18 11:27:21 -08:00
|
|
|
engine->module<TriggerScheduler>()->scheduleOrQueue(¤t->open,
|
2019-12-02 21:29:12 -08:00
|
|
|
TRIGGER_EVENT_UNDEFINED,
|
2020-01-10 13:01:54 -08:00
|
|
|
getTimeNowNt(),
|
2019-12-02 21:29:12 -08:00
|
|
|
current->extra + engine->engineState.auxValveStart,
|
2020-11-05 15:10:44 -08:00
|
|
|
{ auxPlainPinTurnOn, current }
|
2019-12-02 21:29:12 -08:00
|
|
|
);
|
2020-11-06 18:24:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void auxPlainPinTurnOn(AuxActor *current) {
|
|
|
|
NamedOutputPin *output = &enginePins.auxValve[current->valveIndex];
|
|
|
|
output->setHigh();
|
|
|
|
|
|
|
|
scheduleOpen(current);
|
2019-12-02 21:29:12 -08:00
|
|
|
|
|
|
|
angle_t duration = engine->engineState.auxValveEnd - engine->engineState.auxValveStart;
|
|
|
|
|
|
|
|
fixAngle(duration, "duration", CUSTOM_ERR_6557);
|
|
|
|
|
2021-11-18 11:27:21 -08:00
|
|
|
engine->module<TriggerScheduler>()->scheduleOrQueue(¤t->close,
|
2019-12-02 21:29:12 -08:00
|
|
|
TRIGGER_EVENT_UNDEFINED,
|
2020-01-10 13:01:54 -08:00
|
|
|
getTimeNowNt(),
|
2019-12-02 21:29:12 -08:00
|
|
|
current->extra + engine->engineState.auxValveEnd,
|
2020-01-07 15:10:31 -08:00
|
|
|
{ plainPinTurnOff, output }
|
2019-12-02 21:29:12 -08:00
|
|
|
);
|
2019-11-24 09:45:38 -08:00
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void initAuxValves() {
|
2021-01-08 17:01:26 -08:00
|
|
|
if (!isBrainPinValid(engineConfiguration->auxValves[0])) {
|
2017-11-26 19:30:37 -08:00
|
|
|
return;
|
|
|
|
}
|
2019-12-02 21:29:12 -08:00
|
|
|
|
2020-04-05 16:33:33 -07:00
|
|
|
if (!Sensor::hasSensor(SensorType::DriverThrottleIntent)) {
|
2020-05-23 07:46:28 -07:00
|
|
|
firmwareError(CUSTOM_OBD_91, "No TPS for Aux Valves");
|
2019-12-02 21:29:12 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
recalculateAuxValveTiming();
|
2019-12-02 21:29:12 -08:00
|
|
|
|
|
|
|
for (int valveIndex = 0; valveIndex < AUX_DIGITAL_VALVE_COUNT; valveIndex++) {
|
|
|
|
|
|
|
|
for (int phaseIndex = 0; phaseIndex < 2; phaseIndex++) {
|
|
|
|
AuxActor *actor = &engine->auxValves[valveIndex][phaseIndex];
|
|
|
|
actor->phaseIndex = phaseIndex;
|
|
|
|
actor->valveIndex = valveIndex;
|
|
|
|
actor->extra = phaseIndex * 360 + valveIndex * 180;
|
|
|
|
|
2020-11-06 18:24:58 -08:00
|
|
|
scheduleOpen(actor);
|
2019-12-02 21:29:12 -08:00
|
|
|
}
|
|
|
|
}
|
2017-11-26 19:30:37 -08:00
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void recalculateAuxValveTiming() {
|
2021-01-08 17:01:26 -08:00
|
|
|
if (!isBrainPinValid(engineConfiguration->auxValves[0])) {
|
2017-11-26 19:30:37 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-05 16:33:33 -07:00
|
|
|
auto [valid, tps] = Sensor::get(SensorType::DriverThrottleIntent);
|
|
|
|
if (!valid) {
|
2018-01-01 09:56:27 -08:00
|
|
|
// error should be already reported by now
|
|
|
|
return;
|
|
|
|
}
|
2020-04-05 16:33:33 -07:00
|
|
|
|
2021-02-16 06:32:16 -08:00
|
|
|
engine->engineState.auxValveStart = interpolate2d(tps,
|
2021-11-04 20:19:44 -07:00
|
|
|
engineConfiguration->scriptCurve1Bins,
|
|
|
|
engineConfiguration->scriptCurve1);
|
2017-11-25 22:17:37 -08:00
|
|
|
|
2021-02-16 06:32:16 -08:00
|
|
|
engine->engineState.auxValveEnd = interpolate2d(tps,
|
2021-11-04 20:19:44 -07:00
|
|
|
engineConfiguration->scriptCurve2Bins,
|
|
|
|
engineConfiguration->scriptCurve2);
|
2017-12-08 17:04:58 -08:00
|
|
|
|
|
|
|
if (engine->engineState.auxValveStart >= engine->engineState.auxValveEnd) {
|
|
|
|
// this is a fatal error to make this really visible
|
2019-12-02 21:29:12 -08:00
|
|
|
firmwareError(CUSTOM_AUX_OUT_OF_ORDER, "out of order at %.2f %.2f %.2f", tps,
|
2017-12-08 17:04:58 -08:00
|
|
|
engine->engineState.auxValveStart,
|
|
|
|
engine->engineState.auxValveEnd);
|
|
|
|
}
|
2017-11-25 22:17:37 -08:00
|
|
|
}
|