9
9
#include " Settings.h"
10
10
#include " BSP.h"
11
11
#include " ../../configuration.h"
12
-
12
+ # include " main.hpp "
13
13
/*
14
14
* The hardware is laid out as a non-inverting op-amp
15
15
* There is a pullup of 39k(TS100) from the +ve input to 3.9V (1M pulup on TS100)
@@ -38,14 +38,26 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC) {
38
38
39
39
uint32_t valueuV = rawInputmVX10 * 100 ; // shift into uV
40
40
// Now to divide this down by the gain
41
- valueuV = (valueuV) / OP_AMP_GAIN_STAGE;
41
+ valueuV /= OP_AMP_GAIN_STAGE;
42
42
43
43
// Remove uV tipOffset
44
44
if (valueuV >= systemSettings.CalibrationOffset )
45
45
valueuV -= systemSettings.CalibrationOffset ;
46
46
else
47
47
valueuV = 0 ;
48
-
48
+ // Bias removal (Compensating for a temperature related non-linearity
49
+ // This uses the target temperature for the tip to calculate a compensation value for temperature related bias
50
+ // This is not entirely ideal as this means we will be wrong on heat up, but will settle to the correct value
51
+ // This will cause us to underread on the heatup until we reach the target temp
52
+ // Compensation (uV)== ((((80+150*(target_temp_c_x10-1000)/3000)*33000)/4096)*100)/GAIN
53
+ // Reordered with Wolframalpha
54
+ if (currentTempTargetDegC > 0 ) {
55
+ uint32_t compensation = (20625 * ((currentTempTargetDegC*10 ) + 600 )) / 512 ;
56
+ compensation /= OP_AMP_GAIN_STAGE;
57
+ if (valueuV > compensation) {
58
+ valueuV -= compensation;
59
+ }
60
+ }
49
61
return valueuV;
50
62
}
51
63
@@ -69,57 +81,59 @@ int32_t LinearInterpolate(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_
69
81
return y1 + (((((x - x1) * 1000 ) / (x2 - x1)) * (y2 - y1 ))) / 1000 ;
70
82
}
71
83
72
- const uint16_t uVtoDegC[] = { 0 , 0 , //
73
- 175 , 10 , //
74
- 381 , 20 , //
75
- 587 , 30 , //
76
- 804 , 40 , //
77
- 1005 , 50 , //
78
- 1007 , 60 , //
79
- 1107 , 70 , //
80
- 1310 , 80 , //
81
- 1522 , 90 , //
82
- 1731 , 100 , //
83
- 1939 , 110 , //
84
- 2079 , 120 , //
85
- 2265 , 130 , //
86
- 2470 , 140 , //
87
- 2676 , 150 , //
88
- 2899 , 160 , //
89
- 3081 , 170 , //
90
- 3186 , 180 , //
91
- 3422 , 190 , //
92
- 3622 , 200 , //
93
- 3830 , 210 , //
94
- 4044 , 220 , //
95
- 4400 , 230 , //
96
- 4691 , 240 , //
97
- 4989 , 250 , //
98
- 5289 , 260 , //
99
- 5583 , 270 , //
100
- 5879 , 280 , //
101
- 6075 , 290 , //
102
- 6332 , 300 , //
103
- 6521 , 310 , //
104
- 6724 , 320 , //
105
- 6929 , 330 , //
106
- 7132 , 340 , //
107
- 7356 , 350 , //
108
- 7561 , 360 , //
109
- 7774 , 370 , //
110
- 7992 , 380 , //
111
- 8200 , 390 , //
112
- 8410 , 400 , //
113
- 8626 , 410 , //
114
- 8849 , 420 , //
115
- 9060 , 430 , //
116
- 9271 , 440 , //
117
- 9531 , 450 , //
118
- 9748 , 460 , //
119
- 10210 , 470 , //
120
- 10219 , 480 , //
121
- 10429 , 490 , //
122
- 10649 , 500 , //
84
+ const uint16_t uVtoDegC[] = { //
85
+ //
86
+ 0 , 0 , //
87
+ 175 , 10 , //
88
+ 381 , 20 , //
89
+ 587 , 30 , //
90
+ 804 , 40 , //
91
+ 1005 , 50 , //
92
+ 1007 , 60 , //
93
+ 1107 , 70 , //
94
+ 1310 , 80 , //
95
+ 1522 , 90 , //
96
+ 1731 , 100 , //
97
+ 1939 , 110 , //
98
+ 2079 , 120 , //
99
+ 2265 , 130 , //
100
+ 2470 , 140 , //
101
+ 2676 , 150 , //
102
+ 2899 , 160 , //
103
+ 3081 , 170 , //
104
+ 3186 , 180 , //
105
+ 3422 , 190 , //
106
+ 3622 , 200 , //
107
+ 3830 , 210 , //
108
+ 4044 , 220 , //
109
+ 4400 , 230 , //
110
+ 4691 , 240 , //
111
+ 4989 , 250 , //
112
+ 5289 , 260 , //
113
+ 5583 , 270 , //
114
+ 5879 , 280 , //
115
+ 6075 , 290 , //
116
+ 6332 , 300 , //
117
+ 6521 , 310 , //
118
+ 6724 , 320 , //
119
+ 6929 , 330 , //
120
+ 7132 , 340 , //
121
+ 7356 , 350 , //
122
+ 7561 , 360 , //
123
+ 7774 , 370 , //
124
+ 7992 , 380 , //
125
+ 8200 , 390 , //
126
+ 8410 , 400 , //
127
+ 8626 , 410 , //
128
+ 8849 , 420 , //
129
+ 9060 , 430 , //
130
+ 9271 , 440 , //
131
+ 9531 , 450 , //
132
+ 9748 , 460 , //
133
+ 10210 , 470 , //
134
+ 10219 , 480 , //
135
+ 10429 , 490 , //
136
+ 10649 , 500 , //
123
137
124
138
};
125
139
uint32_t TipThermoModel::convertuVToDegC (uint32_t tipuVDelta) {
@@ -162,7 +176,7 @@ uint32_t TipThermoModel::getTipInC(bool sampleNow) {
162
176
return currentTipTempInC;
163
177
}
164
178
#ifdef ENABLED_FAHRENHEIT_SUPPORT
165
- uint32_t TipThermoModel::getTipInF (bool sampleNow) {
179
+ uint32_t TipThermoModel::getTipInF (bool sampleNow, uint16_t currentTargetTempCx10 ) {
166
180
uint32_t currentTipTempInF = TipThermoModel::convertTipRawADCToDegF (
167
181
getTipRawTemp (sampleNow));
168
182
currentTipTempInF += convertCtoF (getHandleTemperature () / 10 ); // Add handle offset
0 commit comments