aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-adc.h
diff options
context:
space:
mode:
Diffstat (limited to 'spaghetti-monster/fsm-adc.h')
-rw-r--r--spaghetti-monster/fsm-adc.h24
1 files changed, 11 insertions, 13 deletions
diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h
index 6e39750..241dee4 100644
--- a/spaghetti-monster/fsm-adc.h
+++ b/spaghetti-monster/fsm-adc.h
@@ -40,15 +40,21 @@
#endif
volatile uint8_t irq_adc = 0; // ADC interrupt happened?
-volatile uint8_t irq_adc_stable = 0; // have we passed the 1st junk value yet?
+uint8_t adc_sample_count = 0; // skip the first sample; it's junk
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
+uint16_t adc_raw[2]; // last ADC measurements (0=voltage, 1=temperature)
+uint16_t adc_smooth[2]; // lowpassed ADC measurements (0=voltage, 1=temperature)
+// ADC code is split into two parts:
+// - ISR: runs immediately at each interrupt, does the bare minimum because time is critical here
+// - deferred: the bulk of the logic runs later when time isn't so critical
+uint8_t adc_deferred_enable = 0; // stop waiting and run the deferred code
+void adc_deferred(); // do the actual ADC-related calculations
static inline void ADC_voltage_handler();
volatile uint8_t voltage = 0;
+#ifdef USE_LVP
void low_voltage();
+#endif
#ifdef USE_BATTCHECK
void battcheck();
@@ -63,10 +69,6 @@ void battcheck();
#ifdef USE_THERMAL_REGULATION
-// default 5 seconds between thermal regulation events
-#ifndef THERMAL_WARNING_SECONDS
-#define THERMAL_WARNING_SECONDS 5
-#endif
// try to keep temperature below 45 C
#ifndef DEFAULT_THERM_CEIL
#define DEFAULT_THERM_CEIL 45
@@ -79,14 +81,10 @@ void battcheck();
#ifndef THERM_CAL_OFFSET
#define THERM_CAL_OFFSET 0
#endif
-// temperature now, in C (ish) * 2 (14.1 fixed-point)
+// temperature now, in C (ish)
volatile int16_t temperature;
-// temperature in a few seconds, in C (ish) * 2 (14.1 fixed-point)
-volatile int16_t projected_temperature; // Fight the future!
uint8_t therm_ceil = DEFAULT_THERM_CEIL;
int8_t therm_cal_offset = 0;
-//void low_temperature();
-//void high_temperature();
volatile uint8_t reset_thermal_history = 1;
static inline void ADC_temperature_handler();
#endif // ifdef USE_THERMAL_REGULATION