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 91 of file software_knock.cpp.

91 {
93
94 float frequencyHz = 1000 * bore2frequency(engineConfiguration->cylinderBore);
95 frequencyHz = engineConfiguration->knockDetectionUseDoubleFrequency ? 2 * frequencyHz : frequencyHz;
96
99 }
100
101 knockFilter.configureBandpass(KNOCK_SAMPLE_RATE, frequencyHz, 3);
102
103 #ifdef KNOCK_SPECTROGRAM
105
106 // TODO: use big buffer
107 //buffer = getBigBuffer(BigBufferUser::KnockSpectrogram);
108 // if (!buffer) {
109 // engineConfiguration->enableKnockSpectrogram = false;
110 // return;
111 // }
112 //spectrogramData = buffer.get<SpectrogramData>();
113
115
116 int freqStartConst = START_SPECTRORGAM_FREQUENCY;
117 int minFreqDiff = freqStartConst;
118 int freqStart = 0;
119 float freqStep = 0;
120
121 for (size_t i = 0; i < FFT_SIZE/2; i++)
122 {
123 float freq = float(i * KNOCK_SAMPLE_RATE) / FFT_SIZE;
124 int min = abs(freq - freqStartConst);
125
126 // next after freq start index
127 if(i == spectrogramStartIndex + 1) {
128 freqStep = abs(freq - freqStart);
129 }
130
131 if(min < minFreqDiff) {
132 minFreqDiff = min;
134 freqStart = freq;
135 }
136 }
137
138 engine->module<KnockController>()->m_knockFrequencyStart = (uint16_t)freqStart;
140 }
141 #endif
142
143 // fun fact: we do not offer any ADC channel flexibility like we have for many other kinds of inputs
144 efiSetPadMode("knock ch1", KNOCK_PIN_CH1, PAL_MODE_INPUT_ANALOG);
145#if KNOCK_HAS_CH2
146 efiSetPadMode("knock ch2", KNOCK_PIN_CH2, PAL_MODE_INPUT_ANALOG);
147#endif
148 kt.start();
149 }
150}
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_knockFrequencyStep("Knock: Step Freq", SensorCategory.SENSOR_INPUTS, FieldType.INT, 1096, 1.0, 0.0, 0.0, "Hz")
m_knockFrequencyStart("Knock: Start Freq", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 1094, 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.