rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
trigger_input_comp.cpp File Reference

Detailed Description

Position sensor hardware layer, Using hardware comparator.

Date
Apr 13, 2019
Author
Andrey Belomutskiy, (c) 2012-2020
andreika prome.nosp@m.theu.nosp@m.s.pcb.nosp@m.@gma.nosp@m.il.co.nosp@m.m

Definition in file trigger_input_comp.cpp.

Functions

static void setHysteresis (COMPDriver *comp, int sign)
 
static void comp_shaft_callback (COMPDriver *comp)
 
static void comp_cam_callback (COMPDriver *comp)
 
void onEcuStartTriggerImplementation ()
 
static int getDacValue (uint8_t voltage)
 
void startTriggerInputPins ()
 
void stopTriggerInputPins ()
 

Variables

static volatile int centeredDacValue = 127
 
static volatile int toothCnt = 0
 
static volatile int dacHysteresisMin = 1
 
static volatile int dacHysteresisMax = 15
 
static volatile int dacHysteresisDelta = dacHysteresisMin
 
static volatile int hystUpdatePeriodNumEvents = 116
 
static volatile efitick_t prevNt = 0
 
static volatile float curVrFreqNt = 0
 
static volatile float saturatedVrFreqNt = 0
 
static COMPConfig comp_shaft_cfg
 
static bool isCompEnabled = false
 

Function Documentation

◆ comp_cam_callback()

static void comp_cam_callback ( COMPDriver comp)
static

Definition at line 70 of file trigger_input_comp.cpp.

70 {
71 efitick_t stamp = getTimeNowNt();
72
73 hwHandleVvtCamSignal(isRising, stamp, index);
74}
efitick_t getTimeNowNt()
Definition efitime.cpp:19
void hwHandleVvtCamSignal(bool isRising, efitick_t nowNt, int index)
Here is the call graph for this function:

◆ comp_shaft_callback()

static void comp_shaft_callback ( COMPDriver comp)
static

Definition at line 49 of file trigger_input_comp.cpp.

49 {
50 efitick_t stamp = getTimeNowNt();
51
52 uint32_t status = comp_lld_get_status(comp);
53 int isPrimary = (comp == EFI_COMP_PRIMARY_DEVICE);
54
55 if (status & COMP_IRQ_RISING) {
56 hwHandleShaftSignal(isPrimary ? 0 : 1, true, stamp);
57 // shift the threshold down a little bit to avoid false-triggering (threshold hysteresis)
58 setHysteresis(comp, -1);
59 }
60
61 if (status & COMP_IRQ_FALLING) {
62 hwHandleShaftSignal(isPrimary ? 0 : 1, false, stamp);
63 // shift the threshold up a little bit to avoid false-triggering (threshold hysteresis)
64 setHysteresis(comp, 1);
65 }
66}
uint32_t comp_lld_get_status(COMPDriver *compp)
@ COMP_IRQ_FALLING
@ COMP_IRQ_RISING
void hwHandleShaftSignal(int signalIndex, bool isRising, efitick_t timestamp)
static void setHysteresis(COMPDriver *comp, int sign)
Here is the call graph for this function:

◆ getDacValue()

static int getDacValue ( uint8_t  voltage)
static

Definition at line 90 of file trigger_input_comp.cpp.

90 {
91 constexpr float maxDacValue = 255.0f; // 8-bit DAC
92 return (int)efiRound(maxDacValue * (float)voltage * VOLTAGE_1_BYTE_PACKING_DIV / engineConfiguration->adcVcc, 1.0f);
93}
float efiRound(float value, float precision)
Definition efilib.cpp:34
static constexpr engine_configuration_s * engineConfiguration

Referenced by startTriggerInputPins().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onEcuStartTriggerImplementation()

void onEcuStartTriggerImplementation ( )

Definition at line 85 of file trigger_input_comp.cpp.

85 {
86 compInit();
87 compStart(EFI_COMP_PRIMARY_DEVICE, &comp_shaft_cfg);
88}
static COMPConfig comp_shaft_cfg

◆ setHysteresis()

static void setHysteresis ( COMPDriver comp,
int  sign 
)
static

Definition at line 32 of file trigger_input_comp.cpp.

32 {
33 // update the hysteresis threshold, but not for every tooth
34#ifdef EFI_TRIGGER_COMP_ADAPTIVE_HYSTERESIS
36 efitick_t nowNt = getTimeNowNt();
37 curVrFreqNt = (float)toothCnt / (float)(nowNt - prevNt);
39 toothCnt = 0;
40 prevNt = nowNt;
41#ifdef TRIGGER_COMP_EXTREME_LOGGING
42 efiPrintf("* f=%f d=%d", curVrFreqNt * 1000.0f, dacHysteresisDelta);
43#endif /* TRIGGER_COMP_EXTREME_LOGGING */
44 }
45#endif /* EFI_TRIGGER_COMP_ADAPTIVE_HYSTERESIS */
47}
float interpolateClamped(float x1, float y1, float x2, float y2, float x)
void comp_lld_set_dac_value(COMPDriver *compp, uint32_t value)
Set the DAC value used by comp.
static volatile float saturatedVrFreqNt
static volatile int toothCnt
static volatile int centeredDacValue
static volatile int hystUpdatePeriodNumEvents
static volatile efitick_t prevNt
static volatile int dacHysteresisMax
static volatile int dacHysteresisMin
static volatile float curVrFreqNt
static volatile int dacHysteresisDelta

Referenced by comp_shaft_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startTriggerInputPins()

void startTriggerInputPins ( )

Definition at line 95 of file trigger_input_comp.cpp.

95 {
96 if (isCompEnabled) {
97 efiPrintf("startTIPins(): already enabled!");
98 return;
99 }
100
101 centeredDacValue = getDacValue(engineConfiguration->triggerCompCenterVolt); // usually 2.5V resistor divider
102
106
107 // 20 rpm (60_2) = 1000*60/((2*60)*20) = 25 ms for 1 tooth event
109 hystUpdatePeriodNumEvents = engine->triggerCentral.triggerShape.getSize(); // = 116 for "60-2" trigger wheel
110 float saturatedToothDurationUs = 60.0f * US_PER_SECOND_F / satRpm / hystUpdatePeriodNumEvents;
111 saturatedVrFreqNt = 1.0f / US2NT(saturatedToothDurationUs);
112
113 efiPrintf("startTIPins(): cDac=%d hystMin=%d hystMax=%d satRpm=%.0f satFreq*1k=%f period=%d",
115#ifdef EFI_TRIGGER_COMP_ADAPTIVE_HYSTERESIS
116 efiPrintf("startTIPins(): ADAPTIVE_HYSTERESIS enabled!");
117#endif /* EFI_TRIGGER_COMP_ADAPTIVE_HYSTERESIS */
118
119 int channel = EFI_COMP_TRIGGER_CHANNEL; // todo: use getInputCaptureChannel(hwPin);
120
121 // todo: set pin mode to default (analog/comparator)
122 //palSetPadMode(comp_channel_port[channel], comp_channel_pad[channel], PAL_MODE_INPUT_ANALOG);
123
124 // no generic hal support for extended COMP configuration, so we use hal_lld layer...
125 osalSysLock();
126 comp_lld_set_dac_value(EFI_COMP_PRIMARY_DEVICE, centeredDacValue);
127 comp_lld_channel_enable(EFI_COMP_PRIMARY_DEVICE, channel);
128 osalSysUnlock();
129
130 compEnable(EFI_COMP_PRIMARY_DEVICE);
131 isCompEnabled = true;
132}
uint16_t channel
Definition adc_inputs.h:104
TriggerCentral triggerCentral
Definition engine.h:318
TriggerWaveform triggerShape
size_t getSize() const
static EngineAccessor engine
Definition engine.h:413
void comp_lld_channel_enable(COMPDriver *compp, uint32_t channel)
Configures and activates an EXT channel (used by comp)
static int getDacValue(uint8_t voltage)
static bool isCompEnabled
Here is the call graph for this function:

◆ stopTriggerInputPins()

void stopTriggerInputPins ( )

Definition at line 134 of file trigger_input_comp.cpp.

134 {
135 if (!isCompEnabled) {
136 efiPrintf("stopTIPins(): already disabled!");
137 return;
138 }
139
140 efiPrintf("stopTIPins();");
141
142 compDisable(EFI_COMP_PRIMARY_DEVICE);
143 isCompEnabled = false;
144#if 0
145 for (int i = 0; i < TRIGGER_INPUT_PIN_COUNT; i++) {
146 if (isConfigurationChanged(bc.triggerInputPins[i])) {
148 }
149 }
150 if (isConfigurationChanged(camInput)) {
152 }
153#endif
154}
engine_configuration_s & activeConfiguration
brain_input_pin_e triggerInputPins[TRIGGER_INPUT_PIN_COUNT]
static void turnOffTriggerInputPin(int index, bool isTriggerShaft)
Here is the call graph for this function:

Variable Documentation

◆ centeredDacValue

volatile int centeredDacValue = 127
static

Definition at line 18 of file trigger_input_comp.cpp.

Referenced by setHysteresis(), and startTriggerInputPins().

◆ comp_shaft_cfg

COMPConfig comp_shaft_cfg
static
Initial value:
= {
0
}
@ COMP_OUTPUT_NORMAL
@ COMP_IRQ_BOTH
static void comp_shaft_callback(COMPDriver *comp)

Definition at line 77 of file trigger_input_comp.cpp.

Referenced by onEcuStartTriggerImplementation().

◆ curVrFreqNt

volatile float curVrFreqNt = 0
static

Definition at line 26 of file trigger_input_comp.cpp.

Referenced by setHysteresis().

◆ dacHysteresisDelta

volatile int dacHysteresisDelta = dacHysteresisMin
static

Definition at line 22 of file trigger_input_comp.cpp.

Referenced by setHysteresis(), and startTriggerInputPins().

◆ dacHysteresisMax

volatile int dacHysteresisMax = 15
static

Definition at line 21 of file trigger_input_comp.cpp.

Referenced by setHysteresis(), and startTriggerInputPins().

◆ dacHysteresisMin

volatile int dacHysteresisMin = 1
static

Definition at line 20 of file trigger_input_comp.cpp.

Referenced by setHysteresis(), and startTriggerInputPins().

◆ hystUpdatePeriodNumEvents

volatile int hystUpdatePeriodNumEvents = 116
static

Definition at line 23 of file trigger_input_comp.cpp.

Referenced by setHysteresis(), and startTriggerInputPins().

◆ isCompEnabled

bool isCompEnabled = false
static

Definition at line 83 of file trigger_input_comp.cpp.

Referenced by startTriggerInputPins(), and stopTriggerInputPins().

◆ prevNt

volatile efitick_t prevNt = 0
static

Definition at line 24 of file trigger_input_comp.cpp.

Referenced by setHysteresis().

◆ saturatedVrFreqNt

volatile float saturatedVrFreqNt = 0
static

Definition at line 26 of file trigger_input_comp.cpp.

Referenced by setHysteresis(), and startTriggerInputPins().

◆ toothCnt

volatile int toothCnt = 0
static

Definition at line 19 of file trigger_input_comp.cpp.

Referenced by setHysteresis().

Go to the source code of this file.