Skip to content

Commit a3f037f

Browse files
committed
Include some bias removal based on the target temp to linearise the response a bit more
1 parent 27bf2a1 commit a3f037f

File tree

3 files changed

+77
-64
lines changed

3 files changed

+77
-64
lines changed

workspace/TS100/Core/Drivers/BMA223.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool BMA223::initalize() {
3939

4040
}
4141

42-
void BMA223::getAxisReadings(int16_t& x, int16_t& y, int16_t& z) {
42+
void BMA223::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
4343
//The BMA is odd in that its output data width is only 8 bits
4444
//And yet there are MSB and LSB registers _sigh_.
4545
uint8_t sensorData[6] = { 0, 0, 0, 0, 0, 0 };
@@ -48,9 +48,9 @@ void BMA223::getAxisReadings(int16_t& x, int16_t& y, int16_t& z) {
4848
x = y = z = 0;
4949
return;
5050
}
51-
52-
x = sensorData[1] << 5;
53-
y = sensorData[3] << 5;
54-
z = sensorData[5] << 5;
51+
//Shift 6 to make its range ~= the other accelerometers
52+
x = sensorData[1] << 6;
53+
y = sensorData[3] << 6;
54+
z = sensorData[5] << 6;
5555

5656
}

workspace/TS100/Core/Drivers/TipThermoModel.cpp

+69-55
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "Settings.h"
1010
#include "BSP.h"
1111
#include "../../configuration.h"
12-
12+
#include "main.hpp"
1313
/*
1414
* The hardware is laid out as a non-inverting op-amp
1515
* 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) {
3838

3939
uint32_t valueuV = rawInputmVX10 * 100; // shift into uV
4040
//Now to divide this down by the gain
41-
valueuV = (valueuV) / OP_AMP_GAIN_STAGE;
41+
valueuV /= OP_AMP_GAIN_STAGE;
4242

4343
//Remove uV tipOffset
4444
if (valueuV >= systemSettings.CalibrationOffset)
4545
valueuV -= systemSettings.CalibrationOffset;
4646
else
4747
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+
}
4961
return valueuV;
5062
}
5163

@@ -69,57 +81,59 @@ int32_t LinearInterpolate(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_
6981
return y1 + (((((x - x1) * 1000) / (x2 - x1)) * (y2 - y1))) / 1000;
7082
}
7183

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, //
123137

124138
};
125139
uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
@@ -162,7 +176,7 @@ uint32_t TipThermoModel::getTipInC(bool sampleNow) {
162176
return currentTipTempInC;
163177
}
164178
#ifdef ENABLED_FAHRENHEIT_SUPPORT
165-
uint32_t TipThermoModel::getTipInF(bool sampleNow) {
179+
uint32_t TipThermoModel::getTipInF(bool sampleNow, uint16_t currentTargetTempCx10) {
166180
uint32_t currentTipTempInF = TipThermoModel::convertTipRawADCToDegF(
167181
getTipRawTemp(sampleNow));
168182
currentTipTempInF += convertCtoF(getHandleTemperature() / 10); //Add handle offset

workspace/TS100/configuration.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
#define TEMPERATURE_INF 0 // default to 0
9292
#define DESCRIPTION_SCROLL_SPEED 0 // 0: Slow 1: Fast - default to slow
9393

94-
#define TIP_GAIN 210 // 21 uV/C * 10, uV per deg C constant of the tip, Tip uV * 10 / coeff = tip temp
9594

9695
#define OP_AMP_Rf_TS100 750 * 1000 // 750 Kilo-ohms -> From schematic, R1
9796
#define OP_AMP_Rin_TS100 2370 // 2.37 Kilo-ohms -> From schematic, R2
@@ -101,15 +100,15 @@
101100
#define OP_AMP_Rf_TS80 180 * 1000 // 180 Kilo-ohms -> From schematic, R6
102101
#define OP_AMP_Rin_TS80 2000 // 2.0 Kilo-ohms -> From schematic, R3
103102

104-
#define OP_AMP_GAIN_STAGE_TS80 (1 + (OP_AMP_Rf_TS80 / OP_AMP_Rin_TS80))
105-
103+
#define OP_AMP_GAIN_STAGE_TS80 (1 + (OP_AMP_Rf_TS80 / OP_AMP_Rin_TS80))*3
104+
//The *3 here is a fudge factor that I dont like, but havent tracked down root cause _yet_
106105
//Deriving the Voltage div:
107106
// Vin_max = (3.3*(r1+r2))/(r2)
108107
//vdiv = (32768*4)/(vin_max*10)
109108

110109
#ifdef MODEL_TS100
111110
#define VOLTAGE_DIV 467 // 467 - Default divider from schematic
112-
#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV
111+
#define CALIBRATION_OFFSET 1200 // 900 - Default adc offset in uV
113112
#define PID_POWER_LIMIT 70 // Sets the max pwm power limit
114113
#define POWER_LIMIT 0 // 0 watts default limit
115114
#define MAX_POWER_LIMIT 65 //

0 commit comments

Comments
 (0)