rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
trigger_universal.cpp
Go to the documentation of this file.
1/*
2 * @file trigger_universal.cpp
3 *
4 * @date Jan 3, 2017
5 * @author Andrey Belomutskiy, (c) 2012-2020
6 */
7
8#include "pch.h"
9
10#include "trigger_universal.h"
11
12/**
13 * @see getCycleDuration
14 */
16 return operationMode == TWO_STROKE ? 360 : FOUR_STROKE_ENGINE_CYCLE;
17}
18
19/**
20 * last fall aligned at 720 and skipped area is right before 720
21 */
22void addSkippedToothTriggerEvents(TriggerWheel wheel, TriggerWaveform *s, int totalTeethCount, int skippedCount,
23 float toothWidthPercentage, float offset, float engineCycle, float filterLeft, float filterRight) {
24 criticalAssertVoid(totalTeethCount > 0, "total count");
25 criticalAssertVoid(skippedCount >= 0, "skipped count");
26 criticalAssertVoid(toothWidthPercentage < 1, "toothWidthPercentage");
27
28 float oneTooth = engineCycle / totalTeethCount;
29
30 for (int i = 0; i < totalTeethCount - skippedCount - 1; i++) {
31 float angleDown = oneTooth * (i + (1 - toothWidthPercentage));
32 float angleUp = oneTooth * (i + 1);
33 s->addEventClamped(offset + angleDown, TriggerValue::RISE, wheel, filterLeft, filterRight);
34 s->addEventClamped(offset + angleUp, TriggerValue::FALL, wheel, filterLeft, filterRight);
35 }
36
37 float angleDown = oneTooth * (totalTeethCount - skippedCount - 1 + (1 - toothWidthPercentage));
38 s->addEventClamped(offset + angleDown, TriggerValue::RISE, wheel, filterLeft, filterRight);
39 // custom handling of last event in order to avoid rounding error
40 s->addEventClamped(offset + engineCycle, TriggerValue::FALL, wheel, filterLeft, filterRight);
41}
42
43void initializeSkippedToothTrigger(TriggerWaveform *s, int totalTeethCount, int skippedCount,
44 operation_mode_e operationMode, SyncEdge syncEdge) {
45 if (totalTeethCount <= 0) {
46 firmwareError(ObdCode::CUSTOM_OBD_TRIGGER_WAVEFORM, "Invalid total tooth count for missing tooth decoder: %d", totalTeethCount);
48 return;
49 }
50 efiAssertVoid(ObdCode::CUSTOM_NULL_SHAPE, s != NULL, "TriggerWaveform is NULL");
51
52 s->initialize(operationMode, syncEdge);
53
54#if EFI_UNIT_TEST
55 s->knownOperationMode = false;
56#endif // EFI_UNIT_TEST
57
58 s->setTriggerSynchronizationGap(skippedCount + 1);
59 if (totalTeethCount > 6 && skippedCount > 0) {
60 // this gap is not required to synch on perfect signal but is needed to handle to reject cranking transition noise and potentially high rev noise as well
62 }
63 s->shapeWithoutTdc = (totalTeethCount > 1) && (skippedCount == 0);
64 s->isSynchronizationNeeded = (totalTeethCount > 2) && (skippedCount != 0);
65
66
67 addSkippedToothTriggerEvents(TriggerWheel::T_PRIMARY, s, totalTeethCount, skippedCount, 0.5, 0, getEngineCycle(operationMode),
68 NO_LEFT_FILTER, NO_RIGHT_FILTER);
69}
70
84
87
88
89 const float crankW = 360 / 3 / 2;
90
91
93
96
97
98 float a = 2 * crankW;
99
100 // #1/3
101 s->addEvent720(a += crankW, TriggerValue::RISE, crank);
102 s->addEvent720(a += crankW, TriggerValue::FALL, crank);
103 // #2/3
104 s->addEvent720(a += crankW, TriggerValue::RISE, crank);
105 s->addEvent720(a += crankW, TriggerValue::FALL, crank);
106 // #3/3
107 a += crankW;
108 a += crankW;
109
110 // 2nd #1/3
111 s->addEvent720(a += crankW, TriggerValue::RISE, crank);
112 s->addEvent720(a += crankW, TriggerValue::FALL, crank);
113
114 // 2nd #2/3
115 s->addEvent720(a += crankW, TriggerValue::RISE, crank);
116 s->addEvent720(a += crankW, TriggerValue::FALL, crank);
117
118 s->isSynchronizationNeeded = false;
119}
120
121/**
122 * https://rusefi.com/forum/viewtopic.php?f=5&t=1977
123 */
125 float engineCycle = FOUR_STROKE_ENGINE_CYCLE;
127
129
130 float toothWidth = 3 / 20.0;
131
132 addSkippedToothTriggerEvents(TriggerWheel::T_PRIMARY, s, 18, 0, toothWidth, 0, engineCycle,
133 NO_LEFT_FILTER, 720 - 39);
134
135 s->addToothRiseFall(360, /* width*/10.80);
136}
137
138// TT_VVT_BOSCH_QUICK_START
140 // todo: most cam wheels are defined as 'SyncEdge::Rise' or 'SyncEdge::RiseOnly' shall we unify?
142
143 // our preference is to sync not too close to crank sync point
146
147 s->addToothRiseFall(90, /* width*/ 70);
148 s->addToothRiseFall(130, /* width*/ 20);
149 s->addToothRiseFall(220, /* width*/ 20);
150 s->addToothRiseFall(360, /* width*/ 70);
151}
152
153static void commonSymmetrical(TriggerWaveform* s, int count, float gapFrom, float gapTo) {
154 s->shapeWithoutTdc = true;
155
156 // Sync after 2 good teeth
157 for (size_t i = 0; i < 2; i++) {
158 /**
159 * https://github.com/rusefi/rusefi/issues/4943#issuecomment-1376289608
160 * gaps would be nice during running but horrible during running
161 * Hopefully we do not want variable gap logic yet?
162 */
163 s->setTriggerSynchronizationGap3(i, gapFrom, gapTo);
164 }
165
166 float width = 360 / count;
167
168 // Just a single tooth with 50% duty cycle
171}
172
173// Useful for:
174// - Honda 24+1 (set this on crank primary, single tooth cam)
175// - AEM 24+1 CAS wheel (same config as Honda)
178
179 // 2JZ would be global trigger offset 65 but same wheel could be Honda, not hard coding for now
180 commonSymmetrical(s, 12, 0.2f, 3.4f);
181}
182
187
Trigger shape has all the fields needed to describe and decode trigger signal.
void setShapeDefinitionError(bool value)
void initialize(operation_mode_e operationMode, SyncEdge syncEdge)
void setSecondTriggerSynchronizationGap(float syncRatio)
void setTriggerSynchronizationGap(float syncRatio)
void addToothRiseFall(angle_t angle, angle_t width=10, TriggerWheel const channelIndex=TriggerWheel::T_PRIMARY)
void addEventAngle(angle_t angle, TriggerValue const state, TriggerWheel const channelIndex=TriggerWheel::T_PRIMARY)
void addEvent720(angle_t angle, TriggerValue const state, TriggerWheel const channelIndex=TriggerWheel::T_PRIMARY)
void addEvent360(angle_t angle, TriggerValue const state, TriggerWheel const channelIndex=TriggerWheel::T_PRIMARY)
void setTriggerSynchronizationGap3(int index, float syncRatioFrom, float syncRatioTo)
void addEventClamped(angle_t angle, TriggerValue const state, TriggerWheel const channelIndex, float filterLeft, float filterRight)
void firmwareError(ObdCode code, const char *fmt,...)
@ CUSTOM_NULL_SHAPE
@ CUSTOM_OBD_TRIGGER_WAVEFORM
operation_mode_e
@ FOUR_STROKE_TWELVE_TIMES_CRANK_SENSOR
@ FOUR_STROKE_THREE_TIMES_CRANK_SENSOR
@ FOUR_STROKE_CRANK_SENSOR
@ FOUR_STROKE_CAM_SENSOR
@ TWO_STROKE
@ FOUR_STROKE_SIX_TIMES_CRANK_SENSOR
TriggerWheel
float angle_t
SyncEdge
Definition sync_edge.h:3
void configure3ToothCrank(TriggerWaveform *s)
void configureQuickStartSenderWheel(TriggerWaveform *s)
void configureKawaKX450F(TriggerWaveform *s)
void configureOnePlusOne(TriggerWaveform *s)
void addSkippedToothTriggerEvents(TriggerWheel wheel, TriggerWaveform *s, int totalTeethCount, int skippedCount, float toothWidthPercentage, float offset, float engineCycle, float filterLeft, float filterRight)
void configure12ToothCrank(TriggerWaveform *s)
angle_t getEngineCycle(operation_mode_e operationMode)
static void commonSymmetrical(TriggerWaveform *s, int count, float gapFrom, float gapTo)
void initializeSkippedToothTrigger(TriggerWaveform *s, int totalTeethCount, int skippedCount, operation_mode_e operationMode, SyncEdge syncEdge)
void configure3_1_cam(TriggerWaveform *s)
void configure6ToothCrank(TriggerWaveform *s)
uint16_t offset
Definition tunerstudio.h:0
uint16_t count
Definition tunerstudio.h:1