|
4 | 4 |
|
5 | 5 |
|
6 | 6 | #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) |
9 | 9 | // v0 must be the Vgs at which Id=0 |
10 | 10 | { |
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; |
12 | 19 | 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)) { |
21 | 30 | return 0; |
22 | 31 | } |
23 | 32 | // no Idss measurement if Idss exceeds 40 mA, the ATmega's maximum pin current |
24 | 33 | // 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 |
26 | 35 | } |
27 | 36 | } |
28 | 37 | #endif |
@@ -493,7 +502,7 @@ void CheckPins(uint8_t HighPin, uint8_t LowPin, uint8_t TristatePin) |
493 | 502 | #if DebugOut == 5 |
494 | 503 | DisplayValue(i16,-6,' ',3); |
495 | 504 | #endif |
496 | | - i16 =expand_FET_quadratic(ptrans.ice0,adc.hp3,i16); |
| 505 | +// i16 =expand_FET_quadratic(ptrans.ice0,adc.hp3,i16); |
497 | 506 | #if DebugOut == 5 |
498 | 507 | DisplayValue(i16,-6,' ',3); |
499 | 508 | #endif |
|
0 commit comments