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
83
86
87
88 const float crankW = 360 / 3 / 2;
89
90
92
95
96
97 float a = 2 * crankW;
98
99 // #1/3
100 s->addEvent720(a += crankW, TriggerValue::RISE, crank);
101 s->addEvent720(a += crankW, TriggerValue::FALL, crank);
102 // #2/3
103 s->addEvent720(a += crankW, TriggerValue::RISE, crank);
104 s->addEvent720(a += crankW, TriggerValue::FALL, crank);
105 // #3/3
106 a += crankW;
107 a += crankW;
108
109 // 2nd #1/3
110 s->addEvent720(a += crankW, TriggerValue::RISE, crank);
111 s->addEvent720(a += crankW, TriggerValue::FALL, crank);
112
113 // 2nd #2/3
114 s->addEvent720(a += crankW, TriggerValue::RISE, crank);
115 s->addEvent720(a += crankW, TriggerValue::FALL, crank);
116
117 s->isSynchronizationNeeded = false;
118}
119
120/**
121 * https://rusefi.com/forum/viewtopic.php?f=5&t=1977
122 */
124 float engineCycle = FOUR_STROKE_ENGINE_CYCLE;
126
128
129 float toothWidth = 3 / 20.0;
130
131 addSkippedToothTriggerEvents(TriggerWheel::T_PRIMARY, s, 18, 0, toothWidth, 0, engineCycle,
132 NO_LEFT_FILTER, 720 - 39);
133
134 s->addToothRiseFall(360, /* width*/10.80);
135}
136
137// TT_VVT_BOSCH_QUICK_START
139 // todo: most cam wheels are defined as 'SyncEdge::Rise' or 'SyncEdge::RiseOnly' shall we unify?
141
142 // our preference is to sync not too close to crank sync point
145
146 s->addToothRiseFall(90, /* width*/ 70);
147 s->addToothRiseFall(130, /* width*/ 20);
148 s->addToothRiseFall(220, /* width*/ 20);
149 s->addToothRiseFall(360, /* width*/ 70);
150}
151
152static void commonSymmetrical(TriggerWaveform* s, int count, float gapFrom, float gapTo) {
153 s->shapeWithoutTdc = true;
154
155 // Sync after 2 good teeth
156 for (size_t i = 0; i < 2; i++) {
157 /**
158 * https://github.com/rusefi/rusefi/issues/4943#issuecomment-1376289608
159 * gaps would be nice during running but horrible during running
160 * Hopefully we do not want variable gap logic yet?
161 */
162 s->setTriggerSynchronizationGap3(i, gapFrom, gapTo);
163 }
164
165 float width = 360 / count;
166
167 // Just a single tooth with 50% duty cycle
170}
171
172// Useful for:
173// - Honda 24+1 (set this on crank primary, single tooth cam)
174// - AEM 24+1 CAS wheel (same config as Honda)
177
178 // 2JZ would be global trigger offset 65 but same wheel could be Honda, not hard coding for now
179 commonSymmetrical(s, 12, 0.2f, 3.4f);
180}
181
186
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