1
0
forked from me/IronOS

Fix calibration, move to exp moving average

This commit is contained in:
Ben V. Brown
2019-10-08 21:50:50 +11:00
parent 6a39e4bcc8
commit 3fea95c6b1
10 changed files with 61 additions and 33 deletions

View File

@@ -6,7 +6,7 @@
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/> <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="712310659903196406" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-348041022799175818" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>

View File

@@ -0,0 +1,24 @@
/*
* expMovingAverage.h
*
* Created on: 8 Oct 2019
* Author: ralim
*/
#ifndef INC_EXPMOVINGAVERAGE_H_
#define INC_EXPMOVINGAVERAGE_H_
// max size = 127
template<class T, uint8_t weighting>
struct expMovingAverage {
int32_t sum;
void update(T const val) {
sum = ((val * weighting) + (sum * (256 - weighting))) / 256;
}
T average() const {
return sum;
}
};
#endif /* INC_EXPMOVINGAVERAGE_H_ */

View File

@@ -11,25 +11,25 @@
#include <stdint.h> #include <stdint.h>
// max size = 127 // max size = 127
template <class T, uint8_t SIZE> template<class T, uint8_t SIZE>
struct history { struct history {
static const uint8_t size = SIZE; static const uint8_t size = SIZE;
T buf[size]; T buf[size];
int32_t sum; int32_t sum;
uint8_t loc; uint8_t loc;
void update(T const val) { void update(T const val) {
// step backwards so i+1 is the previous value. // step backwards so i+1 is the previous value.
loc = (size+loc-1) % size;
sum -= buf[loc]; sum -= buf[loc];
sum += val; sum += val;
buf[loc] = val; buf[loc] = val;
loc = (loc + 1) % size;
} }
T operator[] (uint8_t i) const { T operator[](uint8_t i) const {
// 0 = newest, size-1 = oldest. // 0 = newest, size-1 = oldest.
i = (i+loc) % size; i = (i + loc) % size;
return buf[i]; return buf[i];
} }

View File

@@ -8,6 +8,7 @@
#include "stdint.h" #include "stdint.h"
#include <history.hpp> #include <history.hpp>
#include "hardware.h" #include "hardware.h"
#include "expMovingAverage.h"
#ifndef POWER_HPP_ #ifndef POWER_HPP_
#define POWER_HPP_ #define POWER_HPP_
@@ -18,17 +19,17 @@
// Once we have feed-forward temp estimation we should be able to better tune this. // Once we have feed-forward temp estimation we should be able to better tune this.
#ifdef MODEL_TS100 #ifdef MODEL_TS100
const int32_t tipMass = 3500; // divide here so division is compile-time. const int32_t tipMass = 45; // X10 watts to raise 1 deg C in 1 second
const uint8_t tipResistance = 85; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80 const uint8_t tipResistance = 85; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80
#endif #endif
#ifdef MODEL_TS80 #ifdef MODEL_TS80
const uint32_t tipMass = 4500; const uint32_t tipMass = 40;
const uint8_t tipResistance = 45; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80 const uint8_t tipResistance = 45; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80
#endif #endif
const uint8_t oscillationPeriod = 8*PID_TIM_HZ; // I term look back value const uint8_t wattHistoryFilter = 24; // I term look back weighting
extern history<uint32_t, oscillationPeriod> x10WattHistory; extern expMovingAverage<uint32_t, wattHistoryFilter> x10WattHistory;
int32_t tempToX10Watts(int32_t rawTemp); int32_t tempToX10Watts(int32_t rawTemp);
void setTipX10Watts(int32_t mw); void setTipX10Watts(int32_t mw);

View File

@@ -502,9 +502,9 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
if (systemSettings.detailedSoldering) { if (systemSettings.detailedSoldering) {
OLED::setFont(1); OLED::setFont(1);
OLED::print(SolderingAdvancedPowerPrompt); // Power: OLED::print(SolderingAdvancedPowerPrompt); // Power:
OLED::printNumber(x10WattHistory[0] / 10, 2); OLED::printNumber(x10WattHistory.average() / 10, 2);
OLED::print(SymbolDot); OLED::print(SymbolDot);
OLED::printNumber(x10WattHistory[0] % 10, 1); OLED::printNumber(x10WattHistory.average()% 10, 1);
OLED::print(SymbolWatts); OLED::print(SymbolWatts);
if (systemSettings.sensitivity && systemSettings.SleepTime) { if (systemSettings.sensitivity && systemSettings.SleepTime) {
@@ -538,10 +538,10 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
OLED::print(SymbolSpace); OLED::print(SymbolSpace);
// Draw heating/cooling symbols // Draw heating/cooling symbols
OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory[0])); OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average()));
} else { } else {
// Draw heating/cooling symbols // Draw heating/cooling symbols
OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory[0])); OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average()));
// We draw boost arrow if boosting, or else gap temp <-> heat // We draw boost arrow if boosting, or else gap temp <-> heat
// indicator // indicator
if (boostModeOn) if (boostModeOn)

View File

@@ -106,7 +106,7 @@ void resetSettings() {
systemSettings.descriptionScrollSpeed = 0; // default to slow systemSettings.descriptionScrollSpeed = 0; // default to slow
#ifdef MODEL_TS100 #ifdef MODEL_TS100
systemSettings.CalibrationOffset = 300; // the adc offset in uV systemSettings.CalibrationOffset = 850; // the adc offset in uV
systemSettings.pidPowerLimit=70; // Sets the max pwm power limit systemSettings.pidPowerLimit=70; // Sets the max pwm power limit
#endif #endif

View File

@@ -50,7 +50,7 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC) {
//Now to divide this down by the gain //Now to divide this down by the gain
valueuV = (valueuV) / op_amp_gain_stage; valueuV = (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;

View File

@@ -563,25 +563,26 @@ static void setTipOffset() {
// If the thermo-couple at the end of the tip, and the handle are at // If the thermo-couple at the end of the tip, and the handle are at
// equilibrium, then the output should be zero, as there is no temperature // equilibrium, then the output should be zero, as there is no temperature
// differential. // differential.
while (systemSettings.CalibrationOffset == 0) {
uint32_t offset = 0; uint32_t offset = 0;
for (uint8_t i = 0; i < 15; i++) { for (uint8_t i = 0; i < 16; i++) {
offset += getTipRawTemp(0); offset += getTipRawTemp(1);
// cycle through the filter a fair bit to ensure we're stable. // cycle through the filter a fair bit to ensure we're stable.
OLED::clearScreen(); OLED::clearScreen();
OLED::setCursor(0, 0); OLED::setCursor(0, 0);
OLED::print(SymbolDot);
for (uint8_t x = 0; x < i / 4; x++)
OLED::print(SymbolDot); OLED::print(SymbolDot);
OLED::refresh(); for (uint8_t x = 0; x < (i / 4); x++)
osDelay(100); OLED::print(SymbolDot);
OLED::refresh();
osDelay(100);
}
systemSettings.CalibrationOffset = TipThermoModel::convertTipRawADCTouV(
offset / 16);
} }
systemSettings.CalibrationOffset = TipThermoModel::convertTipRawADCTouV(
offset / 15);
OLED::clearScreen(); OLED::clearScreen();
OLED::setCursor(0, 0); OLED::setCursor(0, 0);
OLED::drawCheckbox(true); OLED::drawCheckbox(true);
OLED::printNumber(systemSettings.CalibrationOffset,4); OLED::printNumber(systemSettings.CalibrationOffset, 4);
OLED::refresh(); OLED::refresh();
osDelay(1200); osDelay(1200);
} }

View File

@@ -118,7 +118,7 @@ void startPIDTask(void const *argument __unused) {
#else #else
#endif #endif
history<int32_t, PID_TIM_HZ > tempError = { { 0 }, 0, 0 }; history<int32_t, PID_TIM_HZ> tempError = { { 0 }, 0, 0 };
currentTempTargetDegC = 0; // Force start with no output (off). If in sleep / soldering this will currentTempTargetDegC = 0; // Force start with no output (off). If in sleep / soldering this will
// be over-ridden rapidly // be over-ridden rapidly
pidTaskNotification = xTaskGetCurrentTaskHandle(); pidTaskNotification = xTaskGetCurrentTaskHandle();
@@ -126,6 +126,9 @@ void startPIDTask(void const *argument __unused) {
if (ulTaskNotifyTake(pdTRUE, 2000)) { if (ulTaskNotifyTake(pdTRUE, 2000)) {
// This is a call to block this thread until the ADC does its samples // This is a call to block this thread until the ADC does its samples
// Do the reading here to keep the temp calculations churning along
uint32_t currentTipTempInC = TipThermoModel::getTipInC(true);
if (currentTempTargetDegC) { if (currentTempTargetDegC) {
// Cap the max set point to 450C // Cap the max set point to 450C
if (currentTempTargetDegC > (450)) { if (currentTempTargetDegC > (450)) {
@@ -133,7 +136,6 @@ void startPIDTask(void const *argument __unused) {
currentTempTargetDegC = (450); currentTempTargetDegC = (450);
} }
// Convert the current tip to degree's C // Convert the current tip to degree's C
uint32_t currentTipTempInC = TipThermoModel::getTipInC(true);
// As we get close to our target, temp noise causes the system // As we get close to our target, temp noise causes the system
// to be unstable. Use a rolling average to dampen it. // to be unstable. Use a rolling average to dampen it.

View File

@@ -12,7 +12,7 @@
const uint16_t powerPWM = 255; const uint16_t powerPWM = 255;
const uint16_t totalPWM = 255 + 17; //htim2.Init.Period, the full PWM cycle const uint16_t totalPWM = 255 + 17; //htim2.Init.Period, the full PWM cycle
history<uint32_t, oscillationPeriod> x10WattHistory = { { 0 }, 0, 0 }; expMovingAverage<uint32_t, wattHistoryFilter> x10WattHistory = { 0 };
int32_t tempToX10Watts(int32_t rawTemp) { int32_t tempToX10Watts(int32_t rawTemp) {
// mass is in milliJ/*C, rawC is raw per degree C // mass is in milliJ/*C, rawC is raw per degree C