aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-07-08 06:02:27 -0600
committerSelene ToyKeeper2023-07-08 06:02:27 -0600
commit20e8606889bae219626c23051fe7d74b4a67db12 (patch)
treec1521aa9f92d325ca515c42f2a8846880b45ff6e /spaghetti-monster
parentFixed spurious voltage warnings in attiny1616 sleep mode. Fixed by SammysHP. (diff)
downloadanduril-20e8606889bae219626c23051fe7d74b4a67db12.tar.gz
anduril-20e8606889bae219626c23051fe7d74b4a67db12.tar.bz2
anduril-20e8606889bae219626c23051fe7d74b4a67db12.zip
Partially fixed oscillating aux LED voltage colors while asleep.
Amplitude is smaller, frequency is slower, but it can still happen sometimes at color boundaries on models with bright aux LEDs on high mode. (because that's not a measurement error, it's actually oscillating voltage) The Wurkkos TS11 in particular tends to bounce when crossing certain color boundaries, because the aux LEDs are bright and change the voltage enough to push it back and forth across the boundary. Also sped up voltage measurement during first few seconds after turning off, to compensate for slowdown caused by the lowpass filter... while slowing down measurements afterward to slow the oscillation. I tried a bunch of different methods, spanning a range of "stable but slow" to "fast but unstable", and kept code clauses for three representative methods. The one enabled by default is the best compromise I found to reduce the issue as much as possible while keeping readings reasonably responsive.
Diffstat (limited to '')
-rw-r--r--spaghetti-monster/anduril/config-default.h4
-rw-r--r--spaghetti-monster/fsm-adc.c23
-rw-r--r--spaghetti-monster/fsm-wdt.c6
3 files changed, 21 insertions, 12 deletions
diff --git a/spaghetti-monster/anduril/config-default.h b/spaghetti-monster/anduril/config-default.h
index 5023c3b..8f07e47 100644
--- a/spaghetti-monster/anduril/config-default.h
+++ b/spaghetti-monster/anduril/config-default.h
@@ -179,7 +179,9 @@
// if the aux LEDs oscillate between "full battery" and "empty battery"
// while in "voltage" mode, enable this to reduce the amplitude of
// those oscillations
-//#define USE_LOWPASS_WHILE_ASLEEP
+#if (ATTINY==1616) || (ATTINY==1634)
+#define USE_LOWPASS_WHILE_ASLEEP
+#endif
// if there's tint ramping, allow user to set it smooth or stepped
#define USE_STEPPED_TINT_RAMPING
diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c
index d11cca8..31b250f 100644
--- a/spaghetti-monster/fsm-adc.c
+++ b/spaghetti-monster/fsm-adc.c
@@ -323,18 +323,23 @@ static inline void ADC_voltage_handler() {
else if (go_to_standby) { // weaker lowpass while asleep
// occasionally the aux LED color can oscillate during standby,
// while using "voltage" mode ... so try to reduce the oscillation
- uint16_t m = adc_raw[0];
- uint16_t v = adc_smooth[0];
+ uint16_t r = adc_raw[0];
+ uint16_t s = adc_smooth[0];
#if 0
- // fixed-rate lowpass, slow, more stable but takes longer to settle
- if (m < v) { v -= 64; }
- if (m > v) { v += 64; }
+ // fixed-rate lowpass, stable but very slow
+ // (move by only 0.5 ADC units per measurement, 1 ADC unit = 64)
+ if (r < s) { s -= 32; }
+ if (r > s) { s += 32; }
+ #elif 1
+ // 1/8th proportional lowpass, faster but less stable
+ int16_t diff = (r/8) - (s/8);
+ s += diff;
#else
- // weighted lowpass, faster but less stable
- v = (m>>1) + (v>>1);
+ // 50% proportional lowpass, fastest but least stable
+ s = (r>>1) + (s>>1);
#endif
- adc_smooth[0] = v;
- measurement = v;
+ adc_smooth[0] = s;
+ measurement = s;
}
#endif
else measurement = adc_smooth[0];
diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c
index 7c25e9f..64f006e 100644
--- a/spaghetti-monster/fsm-wdt.c
+++ b/spaghetti-monster/fsm-wdt.c
@@ -122,8 +122,10 @@ void WDT_inner() {
#ifndef USE_SLEEP_LVP
return; // no sleep LVP needed if nothing drains power while off
#else
- // stop here, usually... but proceed often enough for sleep LVP to work
- if (0 != (ticks_since_last & 0x07)) return;
+ // stop here, usually... except during the first few seconds asleep,
+ // and once in a while afterward for sleep LVP
+ if ((ticks_since_last > (8 * SLEEP_TICKS_PER_SECOND))
+ && (0 != (ticks_since_last & 0x0f))) return;
adc_trigger = 0; // make sure a measurement will happen
adc_active_now = 1; // use ADC noise reduction sleep mode