diff options
Diffstat (limited to 'spaghetti-monster')
| -rwxr-xr-x | spaghetti-monster/anduril/steps.py | 2 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/tempcheck-mode.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 |
5 files changed, 16 insertions, 12 deletions
diff --git a/spaghetti-monster/anduril/steps.py b/spaghetti-monster/anduril/steps.py index 9056ea3..e19c9a6 100755 --- a/spaghetti-monster/anduril/steps.py +++ b/spaghetti-monster/anduril/steps.py @@ -32,7 +32,7 @@ def nearest_level(target, floor, ceil, steps): #if (! ramp_style): return target; ramp_range = ceil - floor; - ramp_discrete_step_size = ramp_range / (steps-1); + ramp_discrete_step_size = int(ramp_range / (steps-1)); this_level = floor; for i in range(steps): diff --git a/spaghetti-monster/anduril/tempcheck-mode.c b/spaghetti-monster/anduril/tempcheck-mode.c index b4e95ff..b183200 100644 --- a/spaghetti-monster/anduril/tempcheck-mode.c +++ b/spaghetti-monster/anduril/tempcheck-mode.c @@ -52,7 +52,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 96c4af3..4766786 100644 --- a/spaghetti-monster/fsm-adc.c +++ b/spaghetti-monster/fsm-adc.c @@ -227,6 +227,8 @@ void adc_deferred() { #endif } #endif + + if (adc_reset) adc_reset --; } @@ -245,7 +247,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 } @@ -318,10 +320,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 56583bb..fc24712 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 @@ -90,7 +96,6 @@ void battcheck(); 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 |
