From 8b59e880614455bd7bc7d8595de847dd6fe9b5b2 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 14 Nov 2019 01:52:50 -0700 Subject: refactored how interrupts work... set a flag and return immediately, then handle the actual logic later during a less-critical code path Enables smarter responses to standby wakeups. Seems to fix missed button presses during standby, and most of the too-fast sleep ticks. Also eliminated waits from button state measurement, so it can happen easier during standby. (also eliminates the chance of an infinite loop on extra-noisy hardware) Also might improve timing-sensitive interrupts like attiny85 PWM channel 4, or a PWM-DSM hybrid technique I'd like to try. BUT this change also appears to break the thermal sensor, so that needs to be fixed. --- spaghetti-monster/fsm-adc.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index 274fb4d..acb3da6 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -38,9 +38,15 @@ #define VOLTAGE_FUDGE_FACTOR 5 #endif #endif + +volatile uint8_t irq_adc = 0; // ADC interrupt happened? +uint16_t adc_value; // last ADC measurement +uint8_t adcint_enable = 0; // is the current ADC result needed? +void ADC_inner(); // do the actual ADC-related calculations + volatile uint8_t voltage = 0; -volatile uint8_t adcint_enable; // kludge, because adc auto-retrigger won't turn off void low_voltage(); + #ifdef USE_BATTCHECK void battcheck(); #ifdef BATTCHECK_VpT -- cgit v1.2.3 From d4a899d99a366c09f5e38eb9ef71e538e4def2c1 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 14 Nov 2019 01:56:29 -0700 Subject: started refactoring ADC code to split voltage and temperature into their own functions --- spaghetti-monster/fsm-adc.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index acb3da6..5f4d0c8 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -44,6 +44,7 @@ uint16_t adc_value; // last ADC measurement uint8_t adcint_enable = 0; // is the current ADC result needed? void ADC_inner(); // do the actual ADC-related calculations +static inline void ADC_voltage_handler(); volatile uint8_t voltage = 0; void low_voltage(); @@ -56,7 +57,7 @@ void battcheck(); #define USE_BLINK_DIGIT #endif #endif -#endif +#endif // ifdef USE_LVP #ifdef USE_THERMAL_REGULATION @@ -85,7 +86,8 @@ int8_t therm_cal_offset = 0; //void low_temperature(); //void high_temperature(); volatile uint8_t reset_thermal_history = 1; -#endif +static inline void ADC_temperature_handler(); +#endif // ifdef USE_THERMAL_REGULATION inline void ADC_on(); -- cgit v1.2.3 From ae082e6331d75c2cbe339290fbce4e79c2aa2ede Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 14 Nov 2019 18:00:54 -0700 Subject: fixed ADC code; measures and behaves correctly now, and is easier to read... ... but factory reset's auto-calibrate still doesn't get the right values for some reason (manual calibration works, but not auto) --- spaghetti-monster/fsm-adc.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-adc.h') diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index 5f4d0c8..6e39750 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -40,7 +40,9 @@ #endif volatile uint8_t irq_adc = 0; // ADC interrupt happened? -uint16_t adc_value; // last ADC measurement +volatile uint8_t irq_adc_stable = 0; // have we passed the 1st junk value yet? +uint8_t adc_channel = 0; // 0=voltage, 1=temperature +uint16_t adc_values[2]; // last ADC measurements (0=voltage, 1=temperature) uint8_t adcint_enable = 0; // is the current ADC result needed? void ADC_inner(); // do the actual ADC-related calculations -- cgit v1.2.3