aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2020-09-14 03:15:50 -0600
committerSelene ToyKeeper2020-09-14 03:15:50 -0600
commitb8fd5ee8cc6a04a2c214f80c51269a68802309d8 (patch)
tree34d8006cf13d977b5726554d421089e8dd7aeede /spaghetti-monster
parentreorganized code in fsm-events.* to put things in a more coherent order (diff)
parentsteps.py: fixed python3 floating-point error (diff)
downloadanduril-b8fd5ee8cc6a04a2c214f80c51269a68802309d8.tar.gz
anduril-b8fd5ee8cc6a04a2c214f80c51269a68802309d8.tar.bz2
anduril-b8fd5ee8cc6a04a2c214f80c51269a68802309d8.zip
merged upstream fsm branch to get fix for laggy voltage readings on FW3A
(and other build targets which don't use sleep ticks during standby)
Diffstat (limited to 'spaghetti-monster')
-rwxr-xr-xspaghetti-monster/anduril/steps.py2
-rw-r--r--spaghetti-monster/anduril/tempcheck-mode.c2
-rw-r--r--spaghetti-monster/fsm-adc.c9
-rw-r--r--spaghetti-monster/fsm-adc.h7
-rw-r--r--spaghetti-monster/fsm-standby.c8
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
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.