diff --git a/workspace/TS100/Core/Drivers/BMA223.cpp b/workspace/TS100/Core/Drivers/BMA223.cpp index 7cd08530..ac049b07 100755 --- a/workspace/TS100/Core/Drivers/BMA223.cpp +++ b/workspace/TS100/Core/Drivers/BMA223.cpp @@ -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 //And yet there are MSB and LSB registers _sigh_. 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; return; } - - x = sensorData[1] << 5; - y = sensorData[3] << 5; - z = sensorData[5] << 5; + //Shift 6 to make its range ~= the other accelerometers + x = sensorData[1] << 6; + y = sensorData[3] << 6; + z = sensorData[5] << 6; } diff --git a/workspace/TS100/Core/Drivers/TipThermoModel.cpp b/workspace/TS100/Core/Drivers/TipThermoModel.cpp index c472932a..9f840132 100755 --- a/workspace/TS100/Core/Drivers/TipThermoModel.cpp +++ b/workspace/TS100/Core/Drivers/TipThermoModel.cpp @@ -9,7 +9,7 @@ #include "Settings.h" #include "BSP.h" #include "../../configuration.h" - +#include "main.hpp" /* * 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) @@ -38,14 +38,26 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC) { uint32_t valueuV = rawInputmVX10 * 100; // shift into uV //Now to divide this down by the gain - valueuV = (valueuV) / OP_AMP_GAIN_STAGE; + valueuV /= OP_AMP_GAIN_STAGE; //Remove uV tipOffset if (valueuV >= systemSettings.CalibrationOffset) valueuV -= systemSettings.CalibrationOffset; else 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; } @@ -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; } -const uint16_t uVtoDegC[] = { 0, 0, // - 175, 10, // - 381, 20, // - 587, 30, // - 804, 40, // - 1005, 50, // - 1007, 60, // - 1107, 70, // - 1310, 80, // - 1522, 90, // - 1731, 100, // - 1939, 110, // - 2079, 120, // - 2265, 130, // - 2470, 140, // - 2676, 150, // - 2899, 160, // - 3081, 170, // - 3186, 180, // - 3422, 190, // - 3622, 200, // - 3830, 210, // - 4044, 220, // - 4400, 230, // - 4691, 240, // - 4989, 250, // - 5289, 260, // - 5583, 270, // - 5879, 280, // - 6075, 290, // - 6332, 300, // - 6521, 310, // - 6724, 320, // - 6929, 330, // - 7132, 340, // - 7356, 350, // - 7561, 360, // - 7774, 370, // - 7992, 380, // - 8200, 390, // - 8410, 400, // - 8626, 410, // - 8849, 420, // - 9060, 430, // - 9271, 440, // - 9531, 450, // - 9748, 460, // - 10210, 470, // - 10219, 480, // - 10429, 490, // - 10649, 500, // +const uint16_t uVtoDegC[] = { // + // + 0, 0, // + 175, 10, // + 381, 20, // + 587, 30, // + 804, 40, // + 1005, 50, // + 1007, 60, // + 1107, 70, // + 1310, 80, // + 1522, 90, // + 1731, 100, // + 1939, 110, // + 2079, 120, // + 2265, 130, // + 2470, 140, // + 2676, 150, // + 2899, 160, // + 3081, 170, // + 3186, 180, // + 3422, 190, // + 3622, 200, // + 3830, 210, // + 4044, 220, // + 4400, 230, // + 4691, 240, // + 4989, 250, // + 5289, 260, // + 5583, 270, // + 5879, 280, // + 6075, 290, // + 6332, 300, // + 6521, 310, // + 6724, 320, // + 6929, 330, // + 7132, 340, // + 7356, 350, // + 7561, 360, // + 7774, 370, // + 7992, 380, // + 8200, 390, // + 8410, 400, // + 8626, 410, // + 8849, 420, // + 9060, 430, // + 9271, 440, // + 9531, 450, // + 9748, 460, // + 10210, 470, // + 10219, 480, // + 10429, 490, // + 10649, 500, // }; uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { @@ -162,7 +176,7 @@ uint32_t TipThermoModel::getTipInC(bool sampleNow) { return currentTipTempInC; } #ifdef ENABLED_FAHRENHEIT_SUPPORT -uint32_t TipThermoModel::getTipInF(bool sampleNow) { +uint32_t TipThermoModel::getTipInF(bool sampleNow, uint16_t currentTargetTempCx10) { uint32_t currentTipTempInF = TipThermoModel::convertTipRawADCToDegF( getTipRawTemp(sampleNow)); currentTipTempInF += convertCtoF(getHandleTemperature() / 10); //Add handle offset diff --git a/workspace/TS100/configuration.h b/workspace/TS100/configuration.h index eac4a58c..f6dfd544 100644 --- a/workspace/TS100/configuration.h +++ b/workspace/TS100/configuration.h @@ -91,7 +91,6 @@ #define TEMPERATURE_INF 0 // default to 0 #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_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_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: // Vin_max = (3.3*(r1+r2))/(r2) //vdiv = (32768*4)/(vin_max*10) #ifdef MODEL_TS100 #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 POWER_LIMIT 0 // 0 watts default limit #define MAX_POWER_LIMIT 65 //