rusefi-1/firmware/controllers/trigger/decoders/trigger_universal.cpp

117 lines
3.7 KiB
C++
Raw Normal View History

2017-01-03 03:05:22 -08:00
/*
* @file trigger_universal.cpp
*
* @date Jan 3, 2017
2018-01-20 17:55:31 -08:00
* @author Andrey Belomutskiy, (c) 2012-2018
2017-01-03 03:05:22 -08:00
*/
2017-01-03 14:01:42 -08:00
#include "trigger_universal.h"
2017-01-03 03:05:22 -08:00
2017-01-03 14:01:42 -08:00
angle_t getEngineCycle(operation_mode_e operationMode) {
return operationMode == TWO_STROKE ? 360 : 720;
}
2017-01-03 03:05:22 -08:00
2017-01-03 14:01:42 -08:00
void addSkippedToothTriggerEvents(trigger_wheel_e wheel, TriggerShape *s, int totalTeethCount, int skippedCount,
2018-12-25 16:42:27 -08:00
float toothWidth, float offset, float engineCycle, float filterLeft, float filterRight) {
2018-07-25 20:03:04 -07:00
efiAssertVoid(CUSTOM_ERR_6586, totalTeethCount > 0, "total count");
efiAssertVoid(CUSTOM_ERR_6587, skippedCount >= 0, "skipped count");
2017-01-03 14:01:42 -08:00
for (int i = 0; i < totalTeethCount - skippedCount - 1; i++) {
float angleDown = engineCycle / totalTeethCount * (i + (1 - toothWidth));
float angleUp = engineCycle / totalTeethCount * (i + 1);
2018-12-25 16:18:37 -08:00
s->addEvent3(offset + angleDown, wheel, TV_RISE, filterLeft, filterRight);
s->addEvent3(offset + angleUp, wheel, TV_FALL, filterLeft, filterRight);
2017-01-03 14:01:42 -08:00
}
float angleDown = engineCycle / totalTeethCount * (totalTeethCount - skippedCount - 1 + (1 - toothWidth));
2018-12-25 16:18:37 -08:00
s->addEvent3(offset + angleDown, wheel, TV_RISE, filterLeft, filterRight);
s->addEvent3(offset + engineCycle, wheel, TV_FALL, filterLeft, filterRight);
2017-01-03 14:01:42 -08:00
}
void initializeSkippedToothTriggerShapeExt(TriggerShape *s, int totalTeethCount, int skippedCount,
2017-05-15 20:28:49 -07:00
operation_mode_e operationMode DECLARE_ENGINE_PARAMETER_SUFFIX) {
2017-02-23 05:20:24 -08:00
if (totalTeethCount <= 0) {
2017-02-23 11:00:03 -08:00
warning(CUSTOM_OBD_TRIGGER_SHAPE, "totalTeethCount is zero or less: %d", totalTeethCount);
s->shapeDefinitionError = true;
2017-02-23 05:20:24 -08:00
return;
}
2018-07-25 20:03:04 -07:00
efiAssertVoid(CUSTOM_ERR_6588, s != NULL, "TriggerShape is NULL");
2017-01-03 14:01:42 -08:00
s->initialize(operationMode, false);
s->setTriggerSynchronizationGap(skippedCount + 1);
2017-03-06 14:42:16 -08:00
s->isSynchronizationNeeded = (totalTeethCount > 2) && (skippedCount != 0);
2017-01-03 14:01:42 -08:00
addSkippedToothTriggerEvents(T_PRIMARY, s, totalTeethCount, skippedCount, 0.5, 0, getEngineCycle(operationMode),
2018-12-25 16:42:27 -08:00
NO_LEFT_FILTER, NO_RIGHT_FILTER);
2017-01-03 14:01:42 -08:00
}
2017-01-03 03:05:22 -08:00
2017-12-13 18:17:32 -08:00
2018-12-25 16:42:27 -08:00
void configureOnePlusOne(TriggerShape *s, operation_mode_e operationMode) {
2017-12-13 18:17:32 -08:00
float engineCycle = getEngineCycle(operationMode);
s->initialize(FOUR_STROKE_CAM_SENSOR, true);
2018-12-25 08:51:49 -08:00
s->addEvent720(180, T_PRIMARY, TV_RISE);
s->addEvent720(360, T_PRIMARY, TV_FALL);
2017-12-13 18:17:32 -08:00
2018-12-25 08:51:49 -08:00
s->addEvent720(540, T_SECONDARY, TV_RISE);
s->addEvent720(720, T_SECONDARY, TV_FALL);
2017-12-13 18:17:32 -08:00
s->isSynchronizationNeeded = false;
s->useOnlyPrimaryForSync = true;
}
2018-12-25 16:42:27 -08:00
void configureOnePlus60_2(TriggerShape *s, operation_mode_e operationMode) {
2017-12-13 18:17:32 -08:00
s->initialize(FOUR_STROKE_CAM_SENSOR, true);
int totalTeethCount = 60;
int skippedCount = 2;
2018-12-25 08:51:49 -08:00
s->addEvent720(2, T_PRIMARY, TV_RISE);
2018-12-25 16:42:27 -08:00
addSkippedToothTriggerEvents(T_SECONDARY, s, totalTeethCount, skippedCount, 0.5, 0, 360, 2, 20);
2018-12-25 08:51:49 -08:00
s->addEvent720(20, T_PRIMARY, TV_FALL);
2018-12-25 16:42:27 -08:00
addSkippedToothTriggerEvents(T_SECONDARY, s, totalTeethCount, skippedCount, 0.5, 0, 360, 20, NO_RIGHT_FILTER);
2017-12-13 18:17:32 -08:00
addSkippedToothTriggerEvents(T_SECONDARY, s, totalTeethCount, skippedCount, 0.5, 360, 360, NO_LEFT_FILTER,
2018-12-25 16:42:27 -08:00
NO_RIGHT_FILTER);
2017-12-13 18:17:32 -08:00
s->isSynchronizationNeeded = false;
s->useOnlyPrimaryForSync = true;
}
2018-12-25 16:42:27 -08:00
void configure3_1_cam(TriggerShape *s, operation_mode_e operationMode) {
2017-12-13 18:17:32 -08:00
s->initialize(FOUR_STROKE_CAM_SENSOR, true);
const float crankW = 360 / 3 / 2;
trigger_wheel_e crank = T_SECONDARY;
2018-12-25 08:51:49 -08:00
s->addEvent720(10, T_PRIMARY, TV_RISE);
s->addEvent720(50, T_PRIMARY, TV_FALL);
2017-12-13 18:17:32 -08:00
float a = 2 * crankW;
// #1/3
2018-12-25 08:51:49 -08:00
s->addEvent720(a += crankW, crank, TV_RISE);
s->addEvent720(a += crankW, crank, TV_FALL);
2017-12-13 18:17:32 -08:00
// #2/3
2018-12-25 08:51:49 -08:00
s->addEvent720(a += crankW, crank, TV_RISE);
s->addEvent720(a += crankW, crank, TV_FALL);
2017-12-13 18:17:32 -08:00
// #3/3
a += crankW;
a += crankW;
// 2nd #1/3
2018-12-25 08:51:49 -08:00
s->addEvent720(a += crankW, crank, TV_RISE);
s->addEvent720(a += crankW, crank, TV_FALL);
2017-12-13 18:17:32 -08:00
// 2nd #2/3
2018-12-25 08:51:49 -08:00
s->addEvent720(a += crankW, crank, TV_RISE);
s->addEvent720(a += crankW, crank, TV_FALL);
2017-12-13 18:17:32 -08:00
s->isSynchronizationNeeded = false;
}