rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
HellenBoardIdFinderBase Class Reference

#include <hellen_board_id.h>

Inheritance diagram for HellenBoardIdFinderBase:
Inheritance graph
[legend]
Collaboration diagram for HellenBoardIdFinderBase:
Collaboration graph
[legend]

Public Member Functions

float calc (float Tc1_us, float Tc2_us, float Rest, float C, bool testOnlyMajorSeries, float *Rmeasured, float *Cest, int *rIdx)
 
float findClosestResistor (float R, bool testOnlyMajorSeries, int *rIdx)
 
float calcEstimatedResistance (float Tc1_us, float C)
 

Data Fields

HellenBoardIdFinderState state
 

Detailed Description

Definition at line 51 of file hellen_board_id.h.

Member Function Documentation

◆ calc()

float HellenBoardIdFinderBase::calc ( float  Tc1_us,
float  Tc2_us,
float  Rest,
float  C,
bool  testOnlyMajorSeries,
float Rmeasured,
float Cest,
int *  rIdx 
)

Definition at line 147 of file hellen_board_id.cpp.

147 {
148 constexpr float Cest = HELLEN_BOARD_ID_CAPACITOR;
149 // Now calculate the resistance value
150 HellenBoardIdSolver rSolver;
151
152 // solve the equation for R (1 Ohm precision is more than enough)
153 *Rmeasured = rSolver.solve(Tc1_us, Tc2_us, Rest, C, 1.0f);
154
155 // add 22 Ohms for pin's internal resistance
156 // (according to the STM32 datasheets, the voltage drop on an output pin can be up to 0.4V for 8 mA current)
157 // Actual measured value was is in the low-20s on most chips.
158 constexpr float Rinternal = 22.0f;
159 float R = findClosestResistor(*Rmeasured - Rinternal, testOnlyMajorSeries, rIdx);
160
161 // Find the 'real' capacitance value and use it for the next resistor iteration (gives more precision)
162 HellenBoardIdSolver cSolver;
163
164 // We expect the capacitance to be +-10%
165 constexpr float capacitorPrecision = 0.1f;
166 constexpr float Cmin = Cest * (1.0f - capacitorPrecision);
167 constexpr float Cmax = Cest * (1.0f + capacitorPrecision);
168
169 // solve the equation for C (1% precision)
170 *newC = cSolver.solve(Tc1_us, Tc2_us, Cmin, R + Rinternal, 0.01f);
171 // in case something went wrong, we must be in the allowed range
172 *newC = clampF(Cmin, *newC, Cmax);
173
174 return R;
175}
float findClosestResistor(float R, bool testOnlyMajorSeries, int *rIdx)
float solve(float Tc1, float Tc2, float x0, float y, float deltaX)
C

Referenced by detectHellenBoardId().

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

◆ calcEstimatedResistance()

float HellenBoardIdFinderBase::calcEstimatedResistance ( float  Tc1_us,
float  C 
)

Definition at line 137 of file hellen_board_id.cpp.

137 {
138 constexpr float Vcc = 3.3f - 0.1f; // STM32 digital I/O voltage (adjusted for minor voltage drop)
139 constexpr float V01 = Vcc * 0.5f; // let it be 1.6 volts (closer to the datasheet value), the exact value doesn't matter
140 // macos compiler doesn't like log() in constexpr
141 float log1V01Vcc = log(1.0f - V01 / Vcc);
142 // this is only an estimated value, we cannot use it for Board-ID detection!
143 float Rest = -Tc1_us / (C * log1V01Vcc);
144 return Rest;
145}

Referenced by detectHellenBoardId().

Here is the caller graph for this function:

◆ findClosestResistor()

float HellenBoardIdFinderBase::findClosestResistor ( float  R,
bool  testOnlyMajorSeries,
int *  rIdx 
)

Definition at line 105 of file hellen_board_id.cpp.

105 {
106 // the first "major" resistor uses less values (with more spacing between them) so that even less precise method cannot fail.
107 static const float rOnlyMajorValues[] = {
108 HELLEN_BOARD_ID_MAJOR_RESISTORS
109 };
110 // the minor resistor is always measured after the major one, when the exact capacitance is already knows,
111 // so we can use more values and detect them with better precision.
112 static const float rAllValues[] = {
113 // these are equal to the major values and should be used first
114 HELLEN_BOARD_ID_MAJOR_RESISTORS
115 // these are extended series if 256 board IDs aren't enough (16*16).
116 HELLEN_BOARD_ID_MINOR_RESISTORS
117 };
118
119 size_t rValueSize = testOnlyMajorSeries ? efi::size(rOnlyMajorValues) : efi::size(rAllValues);
120
121 *rIdx = -1;
122 float minDelta = 1.e6f;
123 for (size_t i = 0; i < rValueSize; i++) {
124 // Find the nearest resistor by least ratio error
125 float delta = std::abs(1 - (R / rAllValues[i]));
126 if (delta < minDelta) {
127 minDelta = delta;
128 *rIdx = i;
129#ifdef HELLEN_BOARD_ID_DEBUG
130 efiPrintf("* [%d] R = %.0f, delta = %f", i, rAllValues[i], delta);
131#endif /* HELLEN_BOARD_ID_DEBUG */
132 }
133 }
134 return rAllValues[*rIdx];
135}
Definition efilib.h:104
composite packet size

Referenced by calc().

Here is the caller graph for this function:

Field Documentation

◆ state

HellenBoardIdFinderState HellenBoardIdFinderBase::state

Definition at line 60 of file hellen_board_id.h.


The documentation for this class was generated from the following files: