Skip to content

Commit c8e867d

Browse files
author
kubi48
committed
expand_FET_quadratic with rounding
git-svn-id: svn://mikrocontroller.net/transistortester@791 6ebdd44f-5a7e-449c-b779-36259138d2c7
1 parent 662731c commit c8e867d

File tree

32 files changed

+40904
-40882
lines changed

32 files changed

+40904
-40882
lines changed

Software/tags/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Function expand_FET_quadratic mit Rundung.
12
Frequenzgrenze für Periodenmessung auf 33kHz verschoben.
23
Frequency-Scaler (WITH_FREQUENCY_DIVIDER) reorganisiert, 2er Potenz statt Zahl (1 bis 512).
34
Geringerer Flash Benutzung mit Funktionen signed_diff und vcc_diff.

Software/trunk/CheckPins.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,34 @@
44

55

66
#ifdef FET_Idss
7-
uint16_t expand_FET_quadratic(uint16_t v0, uint16_t v1, uint16_t i)
8-
// assuming a datapoint of Vgs=v1, Id=i, tries to calculate Idss (i.e., Id at Vgs=0)
7+
uint16_t expand_FET_quadratic(uint16_t v0, uint16_t v1, uint16_t ii)
8+
// assuming a datapoint of Vgs=v1, Id=ii, tries to calculate Idss (i.e., Id at Vgs=0)
99
// v0 must be the Vgs at which Id=0
1010
{
11-
v1 = v0-v1;
11+
// Quadratic current curve can be calculated by:
12+
// v1 = v0 - v1;
13+
// return (uint32_t)((uint16_t)((uint32_t)(ii * v0) / v1) * v0) / v1;
14+
// But this simpler code need 100 bytes more flash than the following code!
15+
uint8_t drv, dri; // needed for rounding
16+
v1 = v0 - v1;
17+
drv = 0;
18+
dri = 0;
1219
for (;;) {
13-
uint8_t d;
14-
d = v1>>8;
15-
if (d==0) d = 1; // prevent infinite loop
16-
v1 += d; // increase v by 0.4 %; unfortunately the compiler doesn't do this very smartly, insists on creating a 16-bit temporary variable for d
17-
d = i>>8;
18-
i += d;
19-
i += d; // increase i by 0.8 %
20-
if (d > (60000>>8)) {
20+
uint8_t dv, di;
21+
dv = (v1 + drv) >> 8;
22+
drv = (v1 + drv) & 0xff; // remainder of voltage division by 256
23+
// if (dv == 0) dv = 1; // prevent infinite loop
24+
v1 += dv; // increase v by 0.4 %; unfortunately the compiler doesn't do this very smartly, insists on creating a 16-bit temporary variable for d
25+
di = (ii + dri) >> 8;
26+
dri = (ii + dri) & 0xff; // remainder of current division by 256
27+
ii += di;
28+
ii += di; // increase ii by 0.8 %
29+
if (di > (60000>>8)) {
2130
return 0;
2231
}
2332
// no Idss measurement if Idss exceeds 40 mA, the ATmega's maximum pin current
2433
// note that this is actually quite safe, since by the time there's 40 mA running, the Vgs will be 40mA * 20 ohm = 0.8 V, so quite far from 0, so Id will be less than those 40 mA
25-
if (v1 > v0) return i; // V exceeds Vp, so we've reached Vgs=0 without Id exceeding 40 mA, so we can safely do the Idss measurement
34+
if (v1 > v0) return ii; // V exceeds Vp, so we've reached Vgs=0 without Id exceeding 40 mA, so we can safely do the Idss measurement
2635
}
2736
}
2837
#endif
@@ -493,7 +502,7 @@ void CheckPins(uint8_t HighPin, uint8_t LowPin, uint8_t TristatePin)
493502
#if DebugOut == 5
494503
DisplayValue(i16,-6,' ',3);
495504
#endif
496-
i16 =expand_FET_quadratic(ptrans.ice0,adc.hp3,i16);
505+
// i16 =expand_FET_quadratic(ptrans.ice0,adc.hp3,i16);
497506
#if DebugOut == 5
498507
DisplayValue(i16,-6,' ',3);
499508
#endif

0 commit comments

Comments
 (0)