mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Fix calibration, move to exp moving average
This commit is contained in:
24
workspace/TS100/Core/Inc/expMovingAverage.h
Normal file
24
workspace/TS100/Core/Inc/expMovingAverage.h
Normal 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_ */
|
||||
@@ -11,25 +11,25 @@
|
||||
#include <stdint.h>
|
||||
|
||||
// max size = 127
|
||||
template <class T, uint8_t SIZE>
|
||||
template<class T, uint8_t SIZE>
|
||||
struct history {
|
||||
static const uint8_t size = SIZE;
|
||||
static const uint8_t size = SIZE;
|
||||
T buf[size];
|
||||
int32_t sum;
|
||||
uint8_t loc;
|
||||
|
||||
void update(T const val) {
|
||||
// step backwards so i+1 is the previous value.
|
||||
loc = (size+loc-1) % size;
|
||||
|
||||
sum -= buf[loc];
|
||||
sum += 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.
|
||||
i = (i+loc) % size;
|
||||
i = (i + loc) % size;
|
||||
return buf[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "stdint.h"
|
||||
#include <history.hpp>
|
||||
#include "hardware.h"
|
||||
#include "expMovingAverage.h"
|
||||
#ifndef POWER_HPP_
|
||||
#define POWER_HPP_
|
||||
|
||||
@@ -18,17 +19,17 @@
|
||||
// Once we have feed-forward temp estimation we should be able to better tune this.
|
||||
|
||||
#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
|
||||
|
||||
#endif
|
||||
#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
|
||||
|
||||
#endif
|
||||
const uint8_t oscillationPeriod = 8*PID_TIM_HZ; // I term look back value
|
||||
extern history<uint32_t, oscillationPeriod> x10WattHistory;
|
||||
const uint8_t wattHistoryFilter = 24; // I term look back weighting
|
||||
extern expMovingAverage<uint32_t, wattHistoryFilter> x10WattHistory;
|
||||
|
||||
int32_t tempToX10Watts(int32_t rawTemp);
|
||||
void setTipX10Watts(int32_t mw);
|
||||
|
||||
Reference in New Issue
Block a user