2017-01-03 03:05:22 -08:00
|
|
|
/*
|
|
|
|
* @file trigger_universal.cpp
|
|
|
|
*
|
|
|
|
* @date Jan 3, 2017
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2017-01-03 03:05:22 -08:00
|
|
|
*/
|
|
|
|
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2017-01-03 14:01:42 -08:00
|
|
|
#include "trigger_universal.h"
|
2017-01-03 03:05:22 -08:00
|
|
|
|
2020-08-08 14:00:14 -07:00
|
|
|
/**
|
|
|
|
* @see getCycleDuration
|
|
|
|
*/
|
2017-01-03 14:01:42 -08:00
|
|
|
angle_t getEngineCycle(operation_mode_e operationMode) {
|
2019-01-01 11:05:11 -08:00
|
|
|
return operationMode == TWO_STROKE ? 360 : FOUR_STROKE_ENGINE_CYCLE;
|
2017-01-03 14:01:42 -08:00
|
|
|
}
|
2017-01-03 03:05:22 -08:00
|
|
|
|
2019-12-07 22:09:39 -08:00
|
|
|
void addSkippedToothTriggerEvents(trigger_wheel_e wheel, TriggerWaveform *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);
|
2019-05-02 15:05:33 -07:00
|
|
|
s->addEventClamped(offset + angleDown, wheel, TV_RISE, filterLeft, filterRight);
|
|
|
|
s->addEventClamped(offset + angleUp, wheel, TV_FALL, filterLeft, filterRight);
|
2017-01-03 14:01:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
float angleDown = engineCycle / totalTeethCount * (totalTeethCount - skippedCount - 1 + (1 - toothWidth));
|
2019-05-02 15:05:33 -07:00
|
|
|
s->addEventClamped(offset + angleDown, wheel, TV_RISE, filterLeft, filterRight);
|
2021-01-03 10:34:00 -08:00
|
|
|
// custom handling of last event in order to avoid rounding error
|
2019-05-02 15:05:33 -07:00
|
|
|
s->addEventClamped(offset + engineCycle, wheel, TV_FALL, filterLeft, filterRight);
|
2017-01-03 14:01:42 -08:00
|
|
|
}
|
|
|
|
|
2019-12-07 22:09:39 -08:00
|
|
|
void initializeSkippedToothTriggerWaveformExt(TriggerWaveform *s, int totalTeethCount, int skippedCount,
|
2018-12-25 17:09:35 -08:00
|
|
|
operation_mode_e operationMode) {
|
2017-02-23 05:20:24 -08:00
|
|
|
if (totalTeethCount <= 0) {
|
2020-05-23 07:46:28 -07:00
|
|
|
firmwareError(CUSTOM_OBD_TRIGGER_WAVEFORM, "Invalid total tooth count for missing tooth decoder: %d", totalTeethCount);
|
2019-08-07 19:02:08 -07:00
|
|
|
s->setShapeDefinitionError(true);
|
2017-02-23 05:20:24 -08:00
|
|
|
return;
|
|
|
|
}
|
2019-12-07 22:09:39 -08:00
|
|
|
efiAssertVoid(CUSTOM_NULL_SHAPE, s != NULL, "TriggerWaveform is NULL");
|
2020-01-12 07:43:02 -08:00
|
|
|
s->initialize(operationMode);
|
2022-04-03 09:22:47 -07:00
|
|
|
#if EFI_UNIT_TEST
|
|
|
|
s->knownOperationMode = false;
|
|
|
|
#endif // EFI_UNIT_TEST
|
2017-01-03 14:01:42 -08:00
|
|
|
|
|
|
|
s->setTriggerSynchronizationGap(skippedCount + 1);
|
2020-03-05 22:31:04 -08:00
|
|
|
s->shapeWithoutTdc = (totalTeethCount > 1) && (skippedCount == 0);
|
2017-03-06 14:42:16 -08:00
|
|
|
s->isSynchronizationNeeded = (totalTeethCount > 2) && (skippedCount != 0);
|
2017-01-03 14:01:42 -08:00
|
|
|
|
2020-01-14 00:54:46 -08:00
|
|
|
|
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
|
|
|
|
2020-04-25 19:23:53 -07:00
|
|
|
void configureOnePlusOne(TriggerWaveform *s) {
|
2020-01-12 07:43:02 -08:00
|
|
|
s->initialize(FOUR_STROKE_CAM_SENSOR);
|
2017-12-13 18:17:32 -08:00
|
|
|
|
2021-11-14 12:35:11 -08:00
|
|
|
s->addEvent360( 90, T_PRIMARY, TV_RISE);
|
|
|
|
s->addEvent360(180, T_PRIMARY, TV_FALL);
|
2017-12-13 18:17:32 -08:00
|
|
|
|
2021-11-14 12:35:11 -08:00
|
|
|
s->addEvent360(270, T_SECONDARY, TV_RISE);
|
|
|
|
s->addEvent360(360, T_SECONDARY, TV_FALL);
|
2017-12-13 18:17:32 -08:00
|
|
|
|
|
|
|
s->isSynchronizationNeeded = false;
|
|
|
|
s->useOnlyPrimaryForSync = true;
|
|
|
|
}
|
|
|
|
|
2020-04-25 19:23:53 -07:00
|
|
|
void configure3_1_cam(TriggerWaveform *s) {
|
2020-01-12 07:43:02 -08:00
|
|
|
s->initialize(FOUR_STROKE_CAM_SENSOR);
|
2017-12-13 18:17:32 -08:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2020-04-25 16:50:43 -07:00
|
|
|
|
2021-04-08 20:23:01 -07:00
|
|
|
/**
|
|
|
|
* https://rusefi.com/forum/viewtopic.php?f=5&t=1977
|
|
|
|
*/
|
2021-04-08 19:16:14 -07:00
|
|
|
void configureKawaKX450F(TriggerWaveform *s) {
|
2021-04-08 20:23:01 -07:00
|
|
|
float engineCycle = FOUR_STROKE_ENGINE_CYCLE;
|
|
|
|
s->initialize(FOUR_STROKE_CRANK_SENSOR);
|
|
|
|
|
2021-04-12 21:24:52 -07:00
|
|
|
s->setTriggerSynchronizationGap(2.28);
|
|
|
|
|
2021-04-08 20:23:01 -07:00
|
|
|
float toothWidth = 3 / 20.0;
|
|
|
|
|
|
|
|
addSkippedToothTriggerEvents(T_PRIMARY, s, 18, 0, toothWidth, 0, engineCycle,
|
|
|
|
NO_LEFT_FILTER, 720 - 39);
|
2021-04-08 19:16:14 -07:00
|
|
|
|
2021-04-08 20:23:01 -07:00
|
|
|
s->addEvent(0.97, T_PRIMARY, TV_RISE);
|
|
|
|
s->addEvent(1, T_PRIMARY, TV_FALL);
|
2021-04-08 19:16:14 -07:00
|
|
|
}
|
|
|
|
|
2020-04-25 16:50:43 -07:00
|
|
|
void configureQuickStartSenderWheel(TriggerWaveform *s) {
|
2020-04-25 19:23:53 -07:00
|
|
|
s->initialize(FOUR_STROKE_CAM_SENSOR);
|
|
|
|
|
|
|
|
s->useRiseEdge = false;
|
|
|
|
|
2021-11-19 20:56:52 -08:00
|
|
|
int offset = 20;
|
2020-04-25 19:23:53 -07:00
|
|
|
|
2022-01-19 13:39:15 -08:00
|
|
|
// our preference is to sync not too close to crank sync point
|
2022-01-19 17:55:24 -08:00
|
|
|
s->setTriggerSynchronizationGap(0.645);
|
|
|
|
s->setSecondTriggerSynchronizationGap(1.556);
|
2020-04-25 19:23:53 -07:00
|
|
|
|
2021-11-19 20:56:52 -08:00
|
|
|
s->addEvent360(offset + 0, T_PRIMARY, TV_RISE);
|
|
|
|
s->addEvent360(offset + 70, T_PRIMARY, TV_FALL);
|
2020-04-25 19:23:53 -07:00
|
|
|
|
2021-11-19 20:56:52 -08:00
|
|
|
s->addEvent360(offset + 90, T_PRIMARY, TV_RISE);
|
|
|
|
s->addEvent360(offset + 110, T_PRIMARY, TV_FALL);
|
2020-04-25 19:23:53 -07:00
|
|
|
|
2021-11-19 20:56:52 -08:00
|
|
|
s->addEvent360(offset + 180, T_PRIMARY, TV_RISE);
|
|
|
|
s->addEvent360(offset + 200, T_PRIMARY, TV_FALL);
|
2020-04-25 16:50:43 -07:00
|
|
|
|
2021-11-19 20:56:52 -08:00
|
|
|
s->addEvent360(offset + 270, T_PRIMARY, TV_RISE);
|
|
|
|
s->addEvent360(offset + 340, T_PRIMARY, TV_FALL);
|
2020-04-25 16:50:43 -07:00
|
|
|
}
|
2022-05-17 18:38:24 -07:00
|
|
|
|
|
|
|
// Useful for:
|
|
|
|
// - Honda 24+1 (set this on crank primary, single tooth cam)
|
|
|
|
// - AEM 24+1 CAS wheel (same config as Honda)
|
|
|
|
void configure12ToothCrank(TriggerWaveform* s) {
|
|
|
|
s->initialize(FOUR_STROKE_TWELVE_TIMES_CRANK_SENSOR);
|
|
|
|
|
|
|
|
s->useRiseEdge = true;
|
|
|
|
s->shapeWithoutTdc = true;
|
|
|
|
|
|
|
|
// Sync after 3 good teeth
|
|
|
|
for (size_t i = 0; i < 3; i++) {
|
2022-05-24 14:12:36 -07:00
|
|
|
s->setTriggerSynchronizationGap3(i, 0.55f, 1.45f);
|
2022-05-17 18:38:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Just a single tooth with 50% duty cycle
|
|
|
|
s->addEventAngle(15, T_PRIMARY, TV_FALL);
|
|
|
|
s->addEventAngle(30, T_PRIMARY, TV_RISE);
|
|
|
|
}
|