rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Functions
software_knock.h File Reference

Data Structures

struct  SpectrogramData
 

Functions

void initSoftwareKnock ()
 
void knockSamplingCallback (uint8_t cylinderIndex, efitick_t nowNt)
 

Function Documentation

◆ initSoftwareKnock()

void initSoftwareKnock ( )

Definition at line 92 of file software_knock.cpp.

92 {
94
95 float frequencyHz;
96
99 } else {
100 frequencyHz = 1000 * bore2frequency(engineConfiguration->cylinderBore);
101 frequencyHz = engineConfiguration->knockDetectionUseDoubleFrequency ? 2 * frequencyHz : frequencyHz;
102 }
103
104 knockFilter.configureBandpass(KNOCK_SAMPLE_RATE, frequencyHz, 3);
105
106 #ifdef KNOCK_SPECTROGRAM
108
109 // TODO: use big buffer
110 //buffer = getBigBuffer(BigBufferUser::KnockSpectrogram);
111 // if (!buffer) {
112 // engineConfiguration->enableKnockSpectrogram = false;
113 // return;
114 // }
115 //spectrogramData = buffer.get<SpectrogramData>();
116
118
119 int freqStartConst = START_SPECTRORGAM_FREQUENCY;
120 int minFreqDiff = freqStartConst;
121 int freqStart = 0;
122 float freqStep = 0;
123
124 for (size_t i = 0; i < FFT_SIZE/2; i++)
125 {
126 float freq = float(i * KNOCK_SAMPLE_RATE) / FFT_SIZE;
127 int min = abs(freq - freqStartConst);
128
129 // next after freq start index
130 if(i == spectrogramStartIndex + 1) {
131 freqStep = abs(freq - freqStart);
132 }
133
134 if(min < minFreqDiff) {
135 minFreqDiff = min;
137 freqStart = freq;
138 }
139 }
140
141 engine->module<KnockController>()->m_knockFrequencyStart = (uint16_t)freqStart;
143 }
144 #else // KNOCK_SPECTROGRAM
145 criticalAssertVoid(!engineConfiguration->enableKnockSpectrogram, "KNOCK_SPECTROGRAM not enabled");
146 #endif // KNOCK_SPECTROGRAM
147
148 // fun fact: we do not offer any ADC channel flexibility like we have for many other kinds of inputs
149 efiSetPadMode("knock ch1", KNOCK_PIN_CH1, PAL_MODE_INPUT_ANALOG);
150#if KNOCK_HAS_CH2
151 efiSetPadMode("knock ch2", KNOCK_PIN_CH2, PAL_MODE_INPUT_ANALOG);
152#endif
153 kt.start();
154 }
155}
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
void configureBandpass(float samplingFrequency, float centerFrequency, float Q)
Definition biquad.cpp:32
constexpr auto & module()
Definition engine.h:200
static EngineAccessor engine
Definition engine.h:413
static constexpr engine_configuration_s * engineConfiguration
void blackmanharris(float *w, unsigned n, bool sflag)
Definition fft.hpp:188
m_knockFrequencyStart("Knock: Start Freq", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 1090, 1.0, 0.0, 0.0, "Hz")
m_knockFrequencyStep("Knock: Step Freq", SensorCategory.SENSOR_INPUTS, FieldType.INT, 1092, 1.0, 0.0, 0.0, "Hz")
static SpectrogramData * spectrogramData
static size_t spectrogramStartIndex
static Biquad knockFilter
static KnockThread kt
float window[FFT_SIZE]

Referenced by initHardware().

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

◆ knockSamplingCallback()

void knockSamplingCallback ( uint8_t  cylinderIndex,
efitick_t  nowNt 
)

Go to the source code of this file.