rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
hellen_board_id.h
Go to the documentation of this file.
1/**
2 * @file boards/hellen/hellen_board_id.h
3 * @brief Board-Id detector for Hellen boards
4 *
5 * @author andreika <prometheus.pcb@gmail.com>
6 * @author Andrey Belomutskiy, (c) 2012-2022
7 */
8
9#pragma once
10
11// this is used by the detection method and should be visible to the interrupt handler (hellenBoardIdInputCallback)
13{
14public:
15 efitick_t timeChargeNt = 0;
16
21
22#if EFI_PROD_CODE
23 semaphore_t boardId_wake;
24#endif /* EFI_PROD_CODE */
25};
26
27// We need to solve the following equation for R or C:
28// X^Td - X^(Tc1+Td) + X^(Tc2-Tc1) - 1 = 0
29// where: X = exp(-1/(RC))
31{
32public:
33 float fx(float x) override {
34 return exp(k1 / x) - exp(k2 / x) + exp(k3 / x) - 1.0;
35 }
36
37 // first-order derivative
38 float dfx(float x) override {
39 return (-1.0f / (x * x)) * (k1 * exp(k1 / x) - k2 * exp(k2 / x) + k3 * exp(k3 / x));
40 }
41
42 // Newton numerical method (x is R and y is C, or vice-versa)
43 float solve(float Tc1, float Tc2, float x0, float y, float deltaX);
44
45private:
46 // exponential function coefs (see solve())
47 float k1, k2, k3;
48};
49
50
52{
53public:
54 float calc(float Tc1_us, float Tc2_us, float Rest, float C, bool testOnlyMajorSeries, float *Rmeasured, float *Cest, int *rIdx);
55
56 float findClosestResistor(float R, bool testOnlyMajorSeries, int *rIdx);
57 float calcEstimatedResistance(float Tc1_us, float C);
58
59public:
61};
62
63template <size_t NumPins>
65{
66public:
67 HellenBoardIdFinder(brain_pin_e (&rP)[NumPins]) : rPins(rP) {}
68
69 // R1 or R2
70 bool measureChargingTimes(int i, float & Tc1_us, float & Tc2_us);
71 bool measureChargingTimesAveraged(int i, float & Tc1_us, float & Tc2_us);
72
73public:
74 brain_pin_e (&rPins)[NumPins];
76};
77
HellenBoardIdFinderState state
float findClosestResistor(float R, bool testOnlyMajorSeries, int *rIdx)
float calc(float Tc1_us, float Tc2_us, float Rest, float C, bool testOnlyMajorSeries, float *Rmeasured, float *Cest, int *rIdx)
float calcEstimatedResistance(float Tc1_us, float C)
brain_pin_e(& rPins)[NumPins]
HellenBoardIdFinder(brain_pin_e(&rP)[NumPins])
bool measureChargingTimesAveraged(int i, float &Tc1_us, float &Tc2_us)
HellenBoardIdFinderState state
bool measureChargingTimes(int i, float &Tc1_us, float &Tc2_us)
float dfx(float x) override
float fx(float x) override
float solve(float Tc1, float Tc2, float x0, float y, float deltaX)
GPIO_TypeDef * ioportid_t
Port Identifier.
C
Gpio brain_pin_e