From b7d8faa65451a5c71b5b619c605e8623ecd627dc Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 10 Sep 2017 00:27:30 -0600 Subject: Made thermal regulation slightly more prediction-heavy, less noisy at stable state, and slightly smaller. Added a bit of overflow protection since I think I saw it overflow with the prediction weight increased. Uses immediate temperature (instead of avg) for lowpass reset, to make it less noisy at stable state. (more trigger-happy reset switch biases it toward inaction) Avoid using volatile var, to reduce space. Overflow prevention also caps the maximum adjustment step, which should slightly help prevent overshooting the target. --- spaghetti-monster/fsm-adc.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c index 4efb11c..699c6cb 100644 --- a/spaghetti-monster/fsm-adc.c +++ b/spaghetti-monster/fsm-adc.c @@ -177,6 +177,7 @@ ISR(ADC_vect) { } // guess what the temperature will be in a few seconds + int16_t pt; { uint8_t i; int16_t diff; @@ -184,7 +185,7 @@ ISR(ADC_vect) { // algorithm tweaking; not really intended to be modified // how far ahead should we predict? - #define THERM_PREDICTION_STRENGTH 3 + #define THERM_PREDICTION_STRENGTH 4 // how proportional should the adjustments be? #define THERM_DIFF_ATTENUATION 2 // acceptable temperature window size in C @@ -207,24 +208,26 @@ ISR(ADC_vect) { diff = t - temperature_history[0]; // projected_temperature = current temp extended forward by amplified rate of change //projected_temperature = temperature_history[NUM_THERMAL_VALUES_HISTORY-1] + (diff< THERM_FLOOR) { - underheat_lowpass = 0; // we're definitely not too cold - } else if (avg_projected_temperature < THERM_CEIL) { - overheat_lowpass = 0; // we're definitely not too hot + if (pt > THERM_FLOOR) { + underheat_lowpass = 0; // we're probably not too cold + } else if (pt < THERM_CEIL) { + overheat_lowpass = 0; // we're probably not too hot } if (temperature_timer) { -- cgit v1.2.3