~toykeeper/flashlight-firmware/fsm

  • Committer: Selene ToyKeeper
  • Date: 2023-04-26 05:28:30 UTC
  • mto: (483.1.175 anduril2)
  • Revision ID: bzr@toykeeper.net-20230426052830-40z6fwy8ob16nzjz
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
Filename Latest Rev Last Changed Committer Comment Size
..
_the_ 123.1.1 10 years ago Selene Scriven Added TheStar firmwares from _the_ Diff
alexvh 95 10 years ago Selene Scriven Added alexvh's no-OTC off-time memory firmware for Diff
bin 16 10 years ago Selene Scriven Added a dir to hold generally-useful utilities. In Diff
DrJones 24 10 years ago Selene Scriven Started adding contributions from DrJones. Diff
dthoang 111 10 years ago Selene Scriven Added dthoang's Olight Baton-like version of STAR_ Diff
Flashy_Mike 188.1.30 6 years ago Selene Scriven Added Flashy Mike's OTSM example code for later re Diff
Flintrock 188.2.1 7 years ago Selene Scriven Added Flintrock's Bistro-HD 1.0. Diff
gchart 175.1.1 8 years ago Selene Scriven Copied biscotti.c to gchart/babka/babka.c Diff
hello_world 3 10 years ago Selene Scriven Added a 'hello world' test program, based on Jonny Diff
JonnyC 2 10 years ago Selene Scriven Added JonnyC's "STAR" family of firmwares. Diff
loneoceans 188.4.14 6 years ago Selene Scriven added GXB172 firmware from loneoceans (tiny841 boo Diff
Mike_C 169.1.1 8 years ago Selene Scriven Added X85 firmware by Mike C. Diff
odd 151 9 years ago Selene Scriven Added MGdriver by odd. Diff
pilotdog68 150 10 years ago Selene Scriven Added XinTD X3 firmware from pilotdog68. Diff
RMM 174.1.1 6 years ago Selene Scriven Forked Bistro as a base for Dragon. Diff
Tamagotchi 136 10 years ago Selene Scriven Added Tamagotchi/7135x8v2 firmware from fonarevka. Diff
Tido 150.1.3 9 years ago Selene Scriven added BLF-VLD 0.1 Diff
Tom_E 53 10 years ago Selene Scriven Added a STAR-momentary from Tom E, with easy off a Diff
ToyKeeper 15 10 years ago Selene Scriven Moved my sources into ToyKeeper/ directory to keep Diff
tterev3 18 10 years ago Selene Scriven Added PIC10F322 C code examples from tterev3. (one Diff
Werner 106 10 years ago Selene Scriven Added Werner's candle flicker firmware. Diff
INDEX 188.4.16 5 years ago Selene Scriven merged fsm to trunk... lots of updates: + attiny1 27.3 KB Diff Download File
meta 124.1.4 10 years ago Selene Scriven minor top-level doc updates 83 bytes Diff Download File
PRODUCTS 483.1.130 3 years ago Selene Scriven added Emisar DT8 in PRODUCTS 11.4 KB Diff Download File
README 483.1.165 3 years ago Selene ToyKeeper just a couple quick notes on using attiny1616, sin 6.4 KB Diff Download File
TODO 124.1.4 10 years ago Selene Scriven minor top-level doc updates 340 bytes Diff Download File