diff options
| -rw-r--r-- | spaghetti-monster/anduril/anduril.c | 2 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-adc.c | 9 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-adc.h | 7 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-standby.c | 8 |
4 files changed, 15 insertions, 11 deletions
diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 085f4a3..bbc10c0 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -2162,7 +2162,7 @@ void thermal_config_save() { if (val) { int8_t rawtemp = temperature - therm_cal_offset; therm_cal_offset = val - rawtemp; - reset_thermal_history = 1; // invalidate all recent temperature data + adc_reset = 2; // invalidate all recent temperature data } val = config_state_values[1]; diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c index 45a4297..4fc777b 100644 --- a/spaghetti-monster/fsm-adc.c +++ b/spaghetti-monster/fsm-adc.c @@ -222,6 +222,8 @@ void adc_deferred() { #endif } #endif + + if (adc_reset) adc_reset --; } @@ -240,7 +242,7 @@ static inline void ADC_voltage_handler() { uint16_t measurement; // latest ADC value - if (go_to_standby || (adc_smooth[0] < 255)) { + if (adc_reset) { // while asleep, or just after waking, don't lowpass measurement = adc_raw[0]; adc_smooth[0] = measurement; // no lowpass while asleep } @@ -308,10 +310,7 @@ static inline void ADC_temperature_handler() { static uint16_t temperature_history[NUM_TEMP_HISTORY_STEPS]; static int8_t warning_threshold = 0; - if (reset_thermal_history) { // wipe out old data - // don't keep resetting - reset_thermal_history = 0; - + if (adc_reset) { // wipe out old data // ignore average, use latest sample uint16_t foo = adc_raw[1]; adc_smooth[1] = foo; diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index 241dee4..36d4c9c 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -21,6 +21,12 @@ #define FSM_ADC_H +#if defined(USE_LVP) || defined(USE_THERMAL_REGULATION) +// use raw value instead of lowpassed value for the next N measurements +// (2 = 1 for voltage + 1 for temperature) +volatile uint8_t adc_reset = 2; +#endif + #ifdef USE_LVP // default 5 seconds between low-voltage warning events #ifndef VOLTAGE_WARNING_SECONDS @@ -85,7 +91,6 @@ void battcheck(); volatile int16_t temperature; uint8_t therm_ceil = DEFAULT_THERM_CEIL; int8_t therm_cal_offset = 0; -volatile uint8_t reset_thermal_history = 1; static inline void ADC_temperature_handler(); #endif // ifdef USE_THERMAL_REGULATION diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c index b002b91..c450bca 100644 --- a/spaghetti-monster/fsm-standby.c +++ b/spaghetti-monster/fsm-standby.c @@ -73,6 +73,7 @@ void sleep_until_eswitch_pressed() go_to_standby = 0; } if (irq_adc) { // ADC done measuring + adc_reset = 1; // don't lowpass while asleep adc_deferred_enable = 1; adc_deferred(); //ADC_off(); // takes care of itself @@ -84,10 +85,9 @@ void sleep_until_eswitch_pressed() } #endif - #ifdef USE_THERMAL_REGULATION - // forget what the temperature was last time we were on - reset_thermal_history = 1; - #endif + // don't lowpass immediately after waking + // also, reset thermal history + adc_reset = 2; // go back to normal running mode // PCINT not needed any more, and can cause problems if on |
