aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-adc.c
diff options
context:
space:
mode:
Diffstat (limited to 'spaghetti-monster/fsm-adc.c')
-rw-r--r--spaghetti-monster/fsm-adc.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c
index c382a8a..dd43cb9 100644
--- a/spaghetti-monster/fsm-adc.c
+++ b/spaghetti-monster/fsm-adc.c
@@ -291,7 +291,7 @@ static inline void ADC_temperature_handler() {
#define THERM_RESPONSE_MAGNITUDE 128
#endif
// acceptable temperature window size in C
- #define THERM_WINDOW_SIZE 3
+ #define THERM_WINDOW_SIZE 2
// TODO: make this configurable per build target?
// (shorter time for hosts with a lower power-to-mass ratio)
@@ -350,6 +350,19 @@ static inline void ADC_temperature_handler() {
uint16_t ceil = (therm_ceil + 275 - therm_cal_offset - THERM_CAL_OFFSET) << 1;
int16_t offset = pt - ceil;
+ // bias small errors toward zero, while leaving large errors mostly unaffected
+ // (a diff of 1 C is 2 ADC units, * 4 for therm lookahead, so it becomes 8)
+ // (but a diff of 1 C should only send a warning of magnitude 1)
+ // (this also makes it only respond to small errors at the time the error
+ // happened, not after the temperature has stabilized)
+ for(uint8_t foo=0; foo<5; foo++) {
+ if (offset > 0) {
+ offset --;
+ } else if (offset < 0) {
+ offset ++;
+ }
+ }
+
// Too hot?
// (if it's too hot and still getting warmer...)
if ((offset > 0) && (diff > 0)) {