2021-04-04 15:13:21 -07:00
|
|
|
/*
|
|
|
|
* @file knock_logic.h
|
|
|
|
*
|
|
|
|
* @date Apr 04, 2021
|
|
|
|
* @author Andrey Gusakov
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-11-01 20:33:59 -07:00
|
|
|
#include "peak_detect.h"
|
2022-04-29 09:25:33 -07:00
|
|
|
#include "knock_controller_generated.h"
|
2021-11-01 20:33:59 -07:00
|
|
|
|
2021-12-06 18:19:37 -08:00
|
|
|
int getCylinderKnockBank(uint8_t cylinderNumber);
|
2021-11-01 20:33:59 -07:00
|
|
|
|
2024-08-04 10:25:13 -07:00
|
|
|
#define bore2frequency(bore) (900 / (CONST_PI * (bore) / 2))
|
|
|
|
|
2022-08-29 22:57:37 -07:00
|
|
|
class KnockControllerBase : public EngineModule, public knock_controller_s {
|
2021-11-01 20:33:59 -07:00
|
|
|
public:
|
2022-08-29 22:57:37 -07:00
|
|
|
KnockControllerBase() {
|
2022-04-29 12:23:22 -07:00
|
|
|
// start with threshold higher than any possible knock to avoid recording spurious knocks
|
|
|
|
m_knockThreshold = 100;
|
|
|
|
}
|
2022-04-18 05:03:16 -07:00
|
|
|
// EngineModule implementation
|
|
|
|
void onFastCallback() override;
|
|
|
|
|
2021-11-01 20:33:59 -07:00
|
|
|
// onKnockSenseCompleted is the callback from the knock sense driver to report a sensed knock level
|
2024-08-03 12:17:34 -07:00
|
|
|
void onKnockSenseCompleted(uint8_t cylinderNumber, float dbv, float frequency, efitick_t lastKnockTime);
|
2021-11-01 20:33:59 -07:00
|
|
|
|
|
|
|
float getKnockRetard() const;
|
2022-04-18 05:03:16 -07:00
|
|
|
uint32_t getKnockCount() const;
|
|
|
|
|
2022-08-29 22:57:37 -07:00
|
|
|
virtual float getKnockThreshold() const = 0;
|
|
|
|
virtual float getMaximumRetard() const = 0;
|
2021-11-01 20:33:59 -07:00
|
|
|
|
|
|
|
private:
|
2023-09-15 00:59:38 -07:00
|
|
|
using PD = PeakDetect<float, MS2NT(50)>;
|
2021-11-01 20:33:59 -07:00
|
|
|
PD peakDetectors[12];
|
|
|
|
PD allCylinderPeakDetector;
|
|
|
|
};
|
2022-08-29 22:57:37 -07:00
|
|
|
|
|
|
|
class KnockController : public KnockControllerBase {
|
|
|
|
public:
|
|
|
|
float getKnockThreshold() const override;
|
|
|
|
float getMaximumRetard() const override;
|
|
|
|
};
|