1
0
forked from me/IronOS

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

@@ -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,7 +81,9 @@ 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[] = { //
//
0, 0, //
175, 10, // 175, 10, //
381, 20, // 381, 20, //
587, 30, // 587, 30, //
@@ -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 //