Include some bias removal based on the target temp to linearise the response a bit more

This commit is contained in:
Ben V. Brown
2020-12-29 10:44:39 +11:00
parent 27bf2a1711
commit a3f037fd1d
3 changed files with 77 additions and 64 deletions

View File

@@ -39,7 +39,7 @@ bool BMA223::initalize() {
} }
void BMA223::getAxisReadings(int16_t& x, int16_t& y, int16_t& z) { void BMA223::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
//The BMA is odd in that its output data width is only 8 bits //The BMA is odd in that its output data width is only 8 bits
//And yet there are MSB and LSB registers _sigh_. //And yet there are MSB and LSB registers _sigh_.
uint8_t sensorData[6] = { 0, 0, 0, 0, 0, 0 }; 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) {
x = y = z = 0; x = y = z = 0;
return; return;
} }
//Shift 6 to make its range ~= the other accelerometers
x = sensorData[1] << 5; x = sensorData[1] << 6;
y = sensorData[3] << 5; y = sensorData[3] << 6;
z = sensorData[5] << 5; z = sensorData[5] << 6;
} }

View File

@@ -9,7 +9,7 @@
#include "Settings.h" #include "Settings.h"
#include "BSP.h" #include "BSP.h"
#include "../../configuration.h" #include "../../configuration.h"
#include "main.hpp"
/* /*
* The hardware is laid out as a non-inverting op-amp * The hardware is laid out as a non-inverting op-amp
* There is a pullup of 39k(TS100) from the +ve input to 3.9V (1M pulup on TS100) * 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) {
uint32_t valueuV = rawInputmVX10 * 100; // shift into uV uint32_t valueuV = rawInputmVX10 * 100; // shift into uV
//Now to divide this down by the gain //Now to divide this down by the gain
valueuV = (valueuV) / OP_AMP_GAIN_STAGE; valueuV /= OP_AMP_GAIN_STAGE;
//Remove uV tipOffset //Remove uV tipOffset
if (valueuV >= systemSettings.CalibrationOffset) if (valueuV >= systemSettings.CalibrationOffset)
valueuV -= systemSettings.CalibrationOffset; valueuV -= systemSettings.CalibrationOffset;
else else
valueuV = 0; valueuV = 0;
// Bias removal (Compensating for a temperature related non-linearity
// This uses the target temperature for the tip to calculate a compensation value for temperature related bias
// This is not entirely ideal as this means we will be wrong on heat up, but will settle to the correct value
// This will cause us to underread on the heatup until we reach the target temp
// Compensation (uV)== ((((80+150*(target_temp_c_x10-1000)/3000)*33000)/4096)*100)/GAIN
// Reordered with Wolframalpha
if (currentTempTargetDegC > 0) {
uint32_t compensation = (20625 * ((currentTempTargetDegC*10) + 600)) / 512;
compensation /= OP_AMP_GAIN_STAGE;
if (valueuV > compensation) {
valueuV -= compensation;
}
}
return valueuV; return valueuV;
} }
@@ -69,57 +81,59 @@ int32_t LinearInterpolate(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_
return y1 + (((((x - x1) * 1000) / (x2 - x1)) * (y2 - y1))) / 1000; return y1 + (((((x - x1) * 1000) / (x2 - x1)) * (y2 - y1))) / 1000;
} }
const uint16_t uVtoDegC[] = { 0, 0, // const uint16_t uVtoDegC[] = { //
175, 10, // //
381, 20, // 0, 0, //
587, 30, // 175, 10, //
804, 40, // 381, 20, //
1005, 50, // 587, 30, //
1007, 60, // 804, 40, //
1107, 70, // 1005, 50, //
1310, 80, // 1007, 60, //
1522, 90, // 1107, 70, //
1731, 100, // 1310, 80, //
1939, 110, // 1522, 90, //
2079, 120, // 1731, 100, //
2265, 130, // 1939, 110, //
2470, 140, // 2079, 120, //
2676, 150, // 2265, 130, //
2899, 160, // 2470, 140, //
3081, 170, // 2676, 150, //
3186, 180, // 2899, 160, //
3422, 190, // 3081, 170, //
3622, 200, // 3186, 180, //
3830, 210, // 3422, 190, //
4044, 220, // 3622, 200, //
4400, 230, // 3830, 210, //
4691, 240, // 4044, 220, //
4989, 250, // 4400, 230, //
5289, 260, // 4691, 240, //
5583, 270, // 4989, 250, //
5879, 280, // 5289, 260, //
6075, 290, // 5583, 270, //
6332, 300, // 5879, 280, //
6521, 310, // 6075, 290, //
6724, 320, // 6332, 300, //
6929, 330, // 6521, 310, //
7132, 340, // 6724, 320, //
7356, 350, // 6929, 330, //
7561, 360, // 7132, 340, //
7774, 370, // 7356, 350, //
7992, 380, // 7561, 360, //
8200, 390, // 7774, 370, //
8410, 400, // 7992, 380, //
8626, 410, // 8200, 390, //
8849, 420, // 8410, 400, //
9060, 430, // 8626, 410, //
9271, 440, // 8849, 420, //
9531, 450, // 9060, 430, //
9748, 460, // 9271, 440, //
10210, 470, // 9531, 450, //
10219, 480, // 9748, 460, //
10429, 490, // 10210, 470, //
10649, 500, // 10219, 480, //
10429, 490, //
10649, 500, //
}; };
uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
@@ -162,7 +176,7 @@ uint32_t TipThermoModel::getTipInC(bool sampleNow) {
return currentTipTempInC; return currentTipTempInC;
} }
#ifdef ENABLED_FAHRENHEIT_SUPPORT #ifdef ENABLED_FAHRENHEIT_SUPPORT
uint32_t TipThermoModel::getTipInF(bool sampleNow) { uint32_t TipThermoModel::getTipInF(bool sampleNow, uint16_t currentTargetTempCx10) {
uint32_t currentTipTempInF = TipThermoModel::convertTipRawADCToDegF( uint32_t currentTipTempInF = TipThermoModel::convertTipRawADCToDegF(
getTipRawTemp(sampleNow)); getTipRawTemp(sampleNow));
currentTipTempInF += convertCtoF(getHandleTemperature() / 10); //Add handle offset currentTipTempInF += convertCtoF(getHandleTemperature() / 10); //Add handle offset

View File

@@ -91,7 +91,6 @@
#define TEMPERATURE_INF 0 // default to 0 #define TEMPERATURE_INF 0 // default to 0
#define DESCRIPTION_SCROLL_SPEED 0 // 0: Slow 1: Fast - default to slow #define DESCRIPTION_SCROLL_SPEED 0 // 0: Slow 1: Fast - default to slow
#define TIP_GAIN 210 // 21 uV/C * 10, uV per deg C constant of the tip, Tip uV * 10 / coeff = tip temp
#define OP_AMP_Rf_TS100 750 * 1000 // 750 Kilo-ohms -> From schematic, R1 #define OP_AMP_Rf_TS100 750 * 1000 // 750 Kilo-ohms -> From schematic, R1
#define OP_AMP_Rin_TS100 2370 // 2.37 Kilo-ohms -> From schematic, R2 #define OP_AMP_Rin_TS100 2370 // 2.37 Kilo-ohms -> From schematic, R2
@@ -101,15 +100,15 @@
#define OP_AMP_Rf_TS80 180 * 1000 // 180 Kilo-ohms -> From schematic, R6 #define OP_AMP_Rf_TS80 180 * 1000 // 180 Kilo-ohms -> From schematic, R6
#define OP_AMP_Rin_TS80 2000 // 2.0 Kilo-ohms -> From schematic, R3 #define OP_AMP_Rin_TS80 2000 // 2.0 Kilo-ohms -> From schematic, R3
#define OP_AMP_GAIN_STAGE_TS80 (1 + (OP_AMP_Rf_TS80 / OP_AMP_Rin_TS80)) #define OP_AMP_GAIN_STAGE_TS80 (1 + (OP_AMP_Rf_TS80 / OP_AMP_Rin_TS80))*3
//The *3 here is a fudge factor that I dont like, but havent tracked down root cause _yet_
//Deriving the Voltage div: //Deriving the Voltage div:
// Vin_max = (3.3*(r1+r2))/(r2) // Vin_max = (3.3*(r1+r2))/(r2)
//vdiv = (32768*4)/(vin_max*10) //vdiv = (32768*4)/(vin_max*10)
#ifdef MODEL_TS100 #ifdef MODEL_TS100
#define VOLTAGE_DIV 467 // 467 - Default divider from schematic #define VOLTAGE_DIV 467 // 467 - Default divider from schematic
#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV #define CALIBRATION_OFFSET 1200 // 900 - Default adc offset in uV
#define PID_POWER_LIMIT 70 // Sets the max pwm power limit #define PID_POWER_LIMIT 70 // Sets the max pwm power limit
#define POWER_LIMIT 0 // 0 watts default limit #define POWER_LIMIT 0 // 0 watts default limit
#define MAX_POWER_LIMIT 65 // #define MAX_POWER_LIMIT 65 //