aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-adc.h
diff options
context:
space:
mode:
authorSelene ToyKeeper2020-01-29 05:08:14 -0700
committerSelene ToyKeeper2020-01-29 05:08:14 -0700
commit9c0d1832464e4ee7ee8c4c63092ac4337347483b (patch)
tree67eb820b425e7a5e019e7158dda30ebab5e1bbe8 /spaghetti-monster/fsm-adc.h
parentfixed too-slow thermal response (was introduced in the irq-refactor branch) (diff)
downloadanduril-9c0d1832464e4ee7ee8c4c63092ac4337347483b.tar.gz
anduril-9c0d1832464e4ee7ee8c4c63092ac4337347483b.tar.bz2
anduril-9c0d1832464e4ee7ee8c4c63092ac4337347483b.zip
rewrote ADC code to use a continuous lowpass system on all measurements, to eliminate noise and maybe increase precision
(thermal code still needs to be rewritten though)
Diffstat (limited to 'spaghetti-monster/fsm-adc.h')
-rw-r--r--spaghetti-monster/fsm-adc.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h
index 6e39750..f4c1332 100644
--- a/spaghetti-monster/fsm-adc.h
+++ b/spaghetti-monster/fsm-adc.h
@@ -40,11 +40,15 @@
#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;