aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-adc.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* reorganized project files (part 1)Selene ToyKeeper2023-11-021-573/+0
| | | | | (just moved files, didn't change the contents yet, and nothing will work without updating #includes and build scripts and stuff)
* Partially fixed oscillating aux LED voltage colors while asleep.Selene ToyKeeper2023-07-081-9/+14
| | | | | | | | | | | | | | | | | | | | 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.
* Fixed spurious voltage warnings in attiny1616 sleep mode. Fixed by SammysHP.Selene ToyKeeper2023-07-081-9/+7
| | | | | | | | https://budgetlightforum.com/t/anduril-2-feature-change-suggestions/218045/467 I was never able to reproduce the issue here, but the fix seems good and others tested it successfully.
* made sleep voltage work on attiny1616 againSelene ToyKeeper2023-04-261-0/+25
| | | | | (oops, it has no "ADC Noise Reduction" mode... needs different setup code)
* fixed bug behind K93_LOCKOUT_KLUDGE which could exit lockout in solid aux modeSelene ToyKeeper2023-04-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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
* switched the rest of FSM + Anduril to use SPDX license headersSelene ToyKeeper2023-04-171-22/+5
| | | | | | | 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.
* reduced ROM by ~600 bytes by moving all eeprom config values to a "cfg" structSelene ToyKeeper2023-04-161-7/+7
| | | | | (this also made some parts of the code cleaner)
* just whitespace / commentsSelene ToyKeeper2023-03-281-1/+1
|
* fixed voltage calibration resolution on SP10 ProSelene ToyKeeper2022-10-211-2/+2
| | | | | and other devices which use a voltage divider (it was 0.1V per step, and is now 0.05V per step)
* added a compile option for USE_LOWPASS_WHILE_ASLEEP,Selene ToyKeeper2021-12-081-2/+20
| | | | | | | | | | | but it doesn't actually fix the issue I was hoping it'd fix, so it's disabled by default (when the battery is right on a threshold between colors for aux LED "voltage" mode, it can bounce between colors until the cell isn't on the boundary any more... but a simple lowpass doesn't really help) (but I also didn't want to throw out the code, in case it's useful later as a reference for a more effective solution)
* Add Sofirn SP10S (adapter) and dual-voltage logicGabriel Hart2021-01-121-0/+4
|
* Add AVR 1-Series and t1616 board and scriptsGabriel Hart2020-12-181-1/+52
|
* merged fsm branch, mostly to get Lume1 driver supportSelene ToyKeeper2020-10-181-0/+14
|\
| * added support for external thermal sensors in fsm-adc.cSelene ToyKeeper2020-09-071-0/+14
| |
* | merged upstream fsm branch to get fix for laggy voltage readings on FW3ASelene ToyKeeper2020-09-141-5/+4
|\| | | | | | | | | (and other build targets which don't use sleep ticks during standby)
| * attempt to fix laggy voltage readings right after waking, on FW3ASelene ToyKeeper2020-08-231-5/+4
| | | | | | | | | | | | | | | | | | (with no sleep ticks, the voltage value never gets reset to the raw value, and instead only goes through the lowpass filter) (this fix is not yet tested... will test before uploading) (also carries a risk of messing up thermal values after being asleep, so that needs to be tested too)
* | added a voltage calibration / correction function, 7C from battcheck to ↵Selene ToyKeeper2020-07-311-2/+12
|/ | | | configure
* set default thermal response magnitude back to how it was before the KR4 ↵Selene ToyKeeper2020-04-271-1/+1
| | | | updates, because it worked well on many hosts before...
* added tweakable thermal_response_magnitude option, adjusted KR4 thermal ↵Selene ToyKeeper2020-04-191-10/+10
| | | | vars, made KR4 rainbow mode faster
* made thermal response larger when error is large, smaller when error is smallSelene ToyKeeper2020-04-191-2/+8
| | | | | (helps on KR4, but will probably need to add the response magnitude thing to adjust speed per build target)
* made thermal regulation use a smaller target window, and prioritize cooling moreSelene ToyKeeper2020-03-261-3/+3
|
* fixed calc_voltage_divider() (use 10-bit calibration values, not 8-bit)Selene ToyKeeper2020-03-161-1/+1
|
* merged fsm branch (to get adc-rework branch with new thermal regulation)Selene ToyKeeper2020-03-161-243/+253
|\
| * merged some misc fixes from pakutrai, cleaned up comments, removed unused ↵Selene ToyKeeper2020-03-161-2/+3
| | | | | | | | symbols
| * reduced regulation jitter by biasing errors toward zero by a constant amount,Selene ToyKeeper2020-03-161-1/+14
| | | | | | | | | | | | | | which mostly impacts small errors (and reduces jitter during the flat phase of regulation) while leaving large errors pretty much unaffected... also, made acceptable thermal window smaller to make up for this new extra tolerance
| * the ADC sample count doesn't need to be 16-bit any more, and isn't really a ↵Selene ToyKeeper2020-03-151-2/+3
| | | | | | | | | | | | | | | | count any more... ... just a boolean flag for whether this is the first sample or a later sample (so I changed it and reduced the ROM size by ~28 bytes)
| * removed dead comments and dead codeSelene ToyKeeper2020-03-151-28/+2
| |
| * replaced temperature_timer (which wasn't even being used) with a variable ↵Selene ToyKeeper2020-03-151-27/+43
| | | | | | | | | | | | | | | | delay between warnings, so large warnings can remain frequent while small warnings are separated by more time, based on a cumulative error counter which must pass a threshold before the next warning is sent (this is producing good test results so far on D4v2 and D4Sv2)
| * tried to make thermal code a bit less twitchy...Selene ToyKeeper2020-03-131-7/+10
| | | | | | | | | | it regulates really fast on D4, but once it's stable, the adjustments are too large
| * went back to continuous lowpass because it had the best noise reductionSelene ToyKeeper2020-02-281-51/+73
| | | | | | | | | | (also, now treating smoothed ADC values as 11-bit, with the lowest 5 bits chopped off to eliminate noise)
| * brute force method for reducing ADC noise -- average a ridiculous number of ↵Selene ToyKeeper2020-02-051-19/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | samples (because, for some reason, even though 64 samples is plenty in a test program, it ends up being extremely erratic when used inside Anduril... and I'm not sure why) also, use 15-bit ADC values instead of 16 bits, in the temperature logic (to help protect against integer overflows) ... but this code still doesn't work well. It regulates down *very* fast, and then gradually rises until the next extra-fast drop-down. :( ... also, tempcheck mode sometimes changes by 4-5 C between readouts, which is worrisome. ... and factory reset is still broken.
| * still doesn't work, but at least it's a bit less broken than before...Selene ToyKeeper2020-02-051-8/+12
| | | | | | | | | | | | (ceiling value was all wrong, and the response magnitude was way too big) (also, temperatures here are unsigned, since freezing is about 270 in ADC units)
| * first pass at a smaller simpler thermal regulation algorithm...Selene ToyKeeper2020-02-051-75/+52
| | | | | | | | ... doesn't work well, but I'm saving it so I can experiment with other methods and maybe revert back later.
| * saving state of ADC / WDT refactoring before doing more changes... what ↵Selene ToyKeeper2020-01-301-69/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | changed so far: - removed LVP lowpass and thermal regulation lowpass logic; it's probably redundant now - slowed ADC deferred logic timing to 4X per second instead of 16X, because there doesn't seem to be much reason to do it any faster - reduced thermal event rate-limit to just 1 second, for more responsive regulation - added "EV_temperature_okay" signal, to help stop adjustments at an appropriate time instead of going to far - sped up sleep LVP to one measurement every 8 seconds instead of 16, to help the aux LEDs respond to voltage changes faster (effect on standby time is negligible) - make sure the WDT doesn't set the ADC channel or counter... except in standby mode
| * switched to a pseudo-rolling-average method to reduce noise, set prescaler ↵Selene ToyKeeper2020-01-301-8/+13
| | | | | | | | back to 64
| * increased effective ADC resolution by switching from continuous-lowpass to ↵Selene ToyKeeper2020-01-291-64/+43
| | | | | | | | sum-of-discrete-window method
| * remove truncation noise by adding 0.5 to each resultSelene ToyKeeper2020-01-291-24/+22
| | | | | | | | | | (keeps stable values within ~0.46 to ~0.54 range, so truncated result has no noise)
| * rewrote ADC code to use a continuous lowpass system on all measurements, to ↵Selene ToyKeeper2020-01-291-121/+175
| | | | | | | | | | | | eliminate noise and maybe increase precision (thermal code still needs to be rewritten though)
* | initial support for Noctigon KR4Selene ToyKeeper2020-03-051-0/+6
| | | | | | | | | | | | | | | | | | (not complete, but far enough that it installs and runs) New hardware support features: - allow using PCINT other than 0 (PCINT1, PCINT2, etc) - option to ignore voltage ADC while the button is pressed (because my prototype shorts the voltage divider to 0 while the button is down)
* | merged from fsm, mostly to get thermal regulation updatesSelene ToyKeeper2019-12-171-5/+8
|\|
| * fixed too-slow thermal response (was introduced in the irq-refactor branch)Selene ToyKeeper2019-12-171-5/+8
| |
* | calibrated Noctigon K1, changed voltage divider calibration values to 10-bit ↵Selene ToyKeeper2019-11-251-1/+1
| | | | | | | | (was 8-bit before)
* | merged more updates from fsm / irq-refactor branches, finishing up previous ↵Selene ToyKeeper2019-11-201-9/+9
|\| | | | | | | changes
| * reduced build size by a few bytesSelene ToyKeeper2019-11-191-1/+1
| |
| * fixed ADC cycles running 2X as fast as intendedSelene ToyKeeper2019-11-191-8/+8
| |
* | merged fsm updates / irq-refactor branch, to get more stable voltage readingsSelene ToyKeeper2019-11-141-224/+244
|\| | | | | | | | | (and otherwise get recent bugfixes)
| * added a lowpass filter for battery voltage measurementsSelene ToyKeeper2019-11-141-37/+22
| | | | | | | | | | (but only on attiny1634 devices, since it costs a bit of space and isn't strictly necessary)
| * fixed ADC code; measures and behaves correctly now, and is easier to read...Selene ToyKeeper2019-11-141-39/+37
| | | | | | | | | | | | ... but factory reset's auto-calibrate still doesn't get the right values for some reason (manual calibration works, but not auto)
| * started refactoring ADC code to split voltage and temperature into their own ↵Selene ToyKeeper2019-11-141-210/+222
| | | | | | | | functions
| * refactored how interrupts work...Selene ToyKeeper2019-11-141-10/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | set a flag and return immediately, then handle the actual logic later during a less-critical code path Enables smarter responses to standby wakeups. Seems to fix missed button presses during standby, and most of the too-fast sleep ticks. Also eliminated waits from button state measurement, so it can happen easier during standby. (also eliminates the chance of an infinite loop on extra-noisy hardware) Also might improve timing-sensitive interrupts like attiny85 PWM channel 4, or a PWM-DSM hybrid technique I'd like to try. BUT this change also appears to break the thermal sensor, so that needs to be fixed.