aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-04-25 23:28:30 -0600
committerSelene ToyKeeper2023-04-25 23:28:30 -0600
commit847485ca96a6ef99abd19984ec025cf1d6841d3d (patch)
treeed6bdf8458493413417e129e4a0ba7a8b9d8eaf9
parentupdated D4Sv2-tintramp -> Emisar 2-channel build target ... (diff)
downloadanduril-847485ca96a6ef99abd19984ec025cf1d6841d3d.tar.gz
anduril-847485ca96a6ef99abd19984ec025cf1d6841d3d.tar.bz2
anduril-847485ca96a6ef99abd19984ec025cf1d6841d3d.zip
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
Diffstat (limited to '')
-rw-r--r--spaghetti-monster/anduril/aux-leds.c9
-rw-r--r--spaghetti-monster/anduril/cfg-emisar-2ch.h3
-rw-r--r--spaghetti-monster/anduril/cfg-emisar-d1v2-7135-fet.h3
-rw-r--r--spaghetti-monster/anduril/cfg-emisar-d1v2-linear-fet.h3
-rw-r--r--spaghetti-monster/anduril/cfg-emisar-d1v2-nofet.h3
-rw-r--r--spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h3
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h3
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-dm11-sbt90.h3
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-dm11.h3
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-k9.3-tintramp-nofet.h3
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-k9.3.h3
-rw-r--r--spaghetti-monster/fsm-adc.c2
-rw-r--r--spaghetti-monster/fsm-adc.h3
-rw-r--r--spaghetti-monster/fsm-standby.c9
-rw-r--r--spaghetti-monster/fsm-wdt.c3
15 files changed, 16 insertions, 40 deletions
diff --git a/spaghetti-monster/anduril/aux-leds.c b/spaghetti-monster/anduril/aux-leds.c
index d9b23d0..c72eb70 100644
--- a/spaghetti-monster/anduril/aux-leds.c
+++ b/spaghetti-monster/anduril/aux-leds.c
@@ -108,15 +108,6 @@ void rgb_led_update(uint8_t mode, uint8_t arg) {
const uint8_t *colors = rgb_led_colors;
uint8_t actual_color = 0;
if (color < 7) { // normal color
- #ifdef USE_K93_LOCKOUT_KLUDGE
- // FIXME: jank alert: this is dumb
- // this clause does nothing; it just uses up clock cycles
- // because without it, the K9.3's lockout mode fails and returns
- // to "off" after ~5 to 15 seconds when configured for a blinking
- // single color, even though there is no code path from lockout to
- // "off", and it doesn't act like a reboot either (no boot-up blink)
- rainbow = (rainbow + 1 + pseudo_rand() % 5) % 6;
- #endif
actual_color = pgm_read_byte(colors + color);
}
else if (color == 7) { // disco
diff --git a/spaghetti-monster/anduril/cfg-emisar-2ch.h b/spaghetti-monster/anduril/cfg-emisar-2ch.h
index 00ef117..69e1524 100644
--- a/spaghetti-monster/anduril/cfg-emisar-2ch.h
+++ b/spaghetti-monster/anduril/cfg-emisar-2ch.h
@@ -109,6 +109,3 @@
// for consistency with KR4 (not otherwise necessary though)
#define USE_SOFT_FACTORY_RESET
-
-// work around bizarre bug: lockout mode fails when set to solid color blinking
-//#define USE_K93_LOCKOUT_KLUDGE
diff --git a/spaghetti-monster/anduril/cfg-emisar-d1v2-7135-fet.h b/spaghetti-monster/anduril/cfg-emisar-d1v2-7135-fet.h
index 15464db..6df56cf 100644
--- a/spaghetti-monster/anduril/cfg-emisar-d1v2-7135-fet.h
+++ b/spaghetti-monster/anduril/cfg-emisar-d1v2-7135-fet.h
@@ -30,6 +30,3 @@
#endif
#define THERM_FASTER_LEVEL (RAMP_SIZE*9/10) // throttle back faster when high
-
-// work around bizarre bug: lockout mode fails when set to solid color blinking
-#define USE_K93_LOCKOUT_KLUDGE
diff --git a/spaghetti-monster/anduril/cfg-emisar-d1v2-linear-fet.h b/spaghetti-monster/anduril/cfg-emisar-d1v2-linear-fet.h
index c8864bf..c1f7238 100644
--- a/spaghetti-monster/anduril/cfg-emisar-d1v2-linear-fet.h
+++ b/spaghetti-monster/anduril/cfg-emisar-d1v2-linear-fet.h
@@ -28,6 +28,3 @@
#endif
#define THERM_FASTER_LEVEL (RAMP_SIZE*9/10) // throttle back faster when high
-
-// work around bizarre bug: lockout mode fails when set to solid color blinking
-#define USE_K93_LOCKOUT_KLUDGE
diff --git a/spaghetti-monster/anduril/cfg-emisar-d1v2-nofet.h b/spaghetti-monster/anduril/cfg-emisar-d1v2-nofet.h
index ede1b67..a68a333 100644
--- a/spaghetti-monster/anduril/cfg-emisar-d1v2-nofet.h
+++ b/spaghetti-monster/anduril/cfg-emisar-d1v2-nofet.h
@@ -22,6 +22,3 @@
#undef SIMPLE_UI_CEIL
#define SIMPLE_UI_CEIL RAMP_SMOOTH_CEIL
-
-// work around bizarre bug: lockout mode fails when set to solid color blinking
-#define USE_K93_LOCKOUT_KLUDGE
diff --git a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h
index bfbcba0..c9a0b4f 100644
--- a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h
+++ b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h
@@ -86,6 +86,3 @@
// for consistency with KR4 (not otherwise necessary though)
#define USE_SOFT_FACTORY_RESET
-
-// work around bizarre bug: lockout mode fails when set to solid color blinking
-#define USE_K93_LOCKOUT_KLUDGE
diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h b/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h
index e0fc162..7798206 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h
@@ -77,6 +77,3 @@
// added for convenience
#define USE_SOFT_FACTORY_RESET
-
-// work around bizarre bug: lockout mode fails when set to solid color blinking
-#define USE_K93_LOCKOUT_KLUDGE
diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11-sbt90.h b/spaghetti-monster/anduril/cfg-noctigon-dm11-sbt90.h
index 5a978b5..94c9a52 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-dm11-sbt90.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-dm11-sbt90.h
@@ -76,6 +76,3 @@
// added for convenience
#define USE_SOFT_FACTORY_RESET
-
-// work around bizarre bug: lockout mode fails when set to solid color blinking
-#define USE_K93_LOCKOUT_KLUDGE
diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11.h b/spaghetti-monster/anduril/cfg-noctigon-dm11.h
index d9b0b8c..5f3cb80 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-dm11.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-dm11.h
@@ -76,6 +76,3 @@
// added for convenience
#define USE_SOFT_FACTORY_RESET
-
-// work around bizarre bug: lockout mode fails when set to solid color blinking
-#define USE_K93_LOCKOUT_KLUDGE
diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3-tintramp-nofet.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3-tintramp-nofet.h
index b505701..8eb55dc 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-k9.3-tintramp-nofet.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3-tintramp-nofet.h
@@ -83,6 +83,3 @@
// for consistency with KR4 (not otherwise necessary though)
#define USE_SOFT_FACTORY_RESET
-
-// work around bizarre bug: lockout mode fails when set to solid color blinking
-#define USE_K93_LOCKOUT_KLUDGE
diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h
index dfe1d18..bf504d2 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h
@@ -84,6 +84,3 @@ inline void set_level_override(uint8_t level);
// for consistency with KR4 (not otherwise necessary though)
#define USE_SOFT_FACTORY_RESET
-
-// work around bizarre bug: lockout mode fails when set to solid color blinking
-#define USE_K93_LOCKOUT_KLUDGE
diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c
index 5b238aa..0b79767 100644
--- a/spaghetti-monster/fsm-adc.c
+++ b/spaghetti-monster/fsm-adc.c
@@ -244,6 +244,8 @@ void adc_deferred() {
// (and the usual standby level is only ~20 uA)
if (go_to_standby) {
ADC_off();
+ // if any measurements were in progress, they're done now
+ adc_active_now = 0;
// also, only check the battery while asleep, not the temperature
adc_channel = 0;
}
diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h
index 16666f9..b25b650 100644
--- a/spaghetti-monster/fsm-adc.h
+++ b/spaghetti-monster/fsm-adc.h
@@ -32,6 +32,9 @@ volatile uint8_t adc_reset = 2;
#endif
#endif
+#ifdef TICK_DURING_STANDBY
+volatile uint8_t adc_active_now = 0; // sleep LVP needs a different sleep mode
+#endif
volatile uint8_t irq_adc = 0; // ADC interrupt happened?
uint8_t adc_sample_count = 0; // skip the first sample; it's junk
uint8_t adc_channel = 0; // 0=voltage, 1=temperature
diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c
index 50e6e30..2ce3a24 100644
--- a/spaghetti-monster/fsm-standby.c
+++ b/spaghetti-monster/fsm-standby.c
@@ -40,6 +40,15 @@ void sleep_until_eswitch_pressed()
#endif
// configure sleep mode
+ #ifdef TICK_DURING_STANDBY
+ // needs a special sleep mode to get accurate measurements
+ // quickly ... full power-down ends up using more power
+ // overall, and causes some weird issues when the MCU
+ // doesn't stay awake enough cycles to complete a reading
+ if (adc_active_now)
+ set_sleep_mode(SLEEP_MODE_ADC);
+ else
+ #endif
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
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
}