From 583854e37efde7f461e073e735a1736b02d28c70 Mon Sep 17 00:00:00 2001
From: Selene ToyKeeper
Date: Mon, 17 Apr 2023 00:08:32 -0600
Subject: switched the rest of FSM + Anduril to use SPDX license headers
instead of full GPL headers (or all too often, nothing at all)
There are a few "FIXME" entries where I'm not sure about the correct copyright.
---
spaghetti-monster/fsm-wdt.c | 27 +++++----------------------
1 file changed, 5 insertions(+), 22 deletions(-)
(limited to 'spaghetti-monster/fsm-wdt.c')
diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c
index ea2efac..847c7fd 100644
--- a/spaghetti-monster/fsm-wdt.c
+++ b/spaghetti-monster/fsm-wdt.c
@@ -1,24 +1,8 @@
-/*
- * fsm-wdt.c: WDT (Watch Dog Timer) functions for SpaghettiMonster.
- *
- * Copyright (C) 2017 Selene ToyKeeper
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#ifndef FSM_WDT_C
-#define FSM_WDT_C
+// fsm-wdt.c: WDT (Watch Dog Timer) functions for SpaghettiMonster.
+// Copyright (C) 2017-2023 Selene ToyKeeper
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#pragma once
#include
#include
@@ -208,4 +192,3 @@ void WDT_inner() {
#endif
}
-#endif
--
cgit v1.2.3
From 847485ca96a6ef99abd19984ec025cf1d6841d3d Mon Sep 17 00:00:00 2001
From: Selene ToyKeeper
Date: Tue, 25 Apr 2023 23:28:30 -0600
Subject: fixed bug behind K93_LOCKOUT_KLUDGE which could exit lockout in solid
aux mode (also reduced avg standby power by about 15 uA) (also fixed
oscillating voltage mode colors, I think)
The bug happened because sometimes sleep LVP would get triggered, because the
ADC would read zero under some conditions.
This in turn happened because the ADC needs the MCU to be at least partially
awake in order to finish a measurement. So in standby mode, with the MCU only
waking up very briefly to send a sleep tick and go back to sleep, the ADC
required several cycles (like 375ms to 625ms) to finish a single measurement.
This varied depending on how many instructions the MCU executed while it was
awake. In the single-color mode, so few instructions were being executed that
the ADC seemed to time out and abort its measurement, returning a zero. Then a
low voltage warning was sent, which knocked the light back into "Off" mode.
Adding no-op instructions inside the single-color clause was sufficient to
prevent the ADC from timing out, because it kept the MCU awake just barely long
enough. But it was a kludge, and it still took like half a second to finish a
measurement, and the measurements were noisy. It also used more power, because
it required keeping the ADC powered on far too long.
This fix puts the MCU into "ADC Noise Reduction" mode instead, when a voltage
measurement is needed during sleep. It reduces noise to make measurements more
stable... but more importantly, it lets the measurement finish in like 0.5ms
instead of 500ms. So it uses less power and isn't dependent on the number of
calculations the MCU does during each "sleep tick".
As a bonus, this can also measure voltage much more often, while still using
less total energy than before. It was once every 8 seconds, and now it's once
per second.
Avg power use in aux low mode, on a D4Sv2: (avg of 30k samples each)
- before: 101 uA
- after: 86 uA
---
spaghetti-monster/fsm-wdt.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'spaghetti-monster/fsm-wdt.c')
diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c
index 847c7fd..7c25e9f 100644
--- a/spaghetti-monster/fsm-wdt.c
+++ b/spaghetti-monster/fsm-wdt.c
@@ -123,9 +123,10 @@ void WDT_inner() {
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 & 0x3f)) return;
+ if (0 != (ticks_since_last & 0x07)) return;
adc_trigger = 0; // make sure a measurement will happen
+ adc_active_now = 1; // use ADC noise reduction sleep mode
ADC_on(); // enable ADC voltage measurement functions temporarily
#endif
}
--
cgit v1.2.3
From 20e8606889bae219626c23051fe7d74b4a67db12 Mon Sep 17 00:00:00 2001
From: Selene ToyKeeper
Date: Sat, 8 Jul 2023 06:02:27 -0600
Subject: 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.
---
spaghetti-monster/fsm-wdt.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'spaghetti-monster/fsm-wdt.c')
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
--
cgit v1.2.3