The firmware works.
I have off-time reading for mode advance set to 0.5 seconds but the discharge curve of the off-time capacitor is consistent so I could change that to anywhere from probably 0.2 to multiple seconds if I wanted. Recharge is controlled by the micro and takes roughly 25 milliseconds from full discharge so there’s no worry about erroneously high reads or misreads from partial or automatic recharge. Only capacitor tolerance and temperature should affect the timing.
The default mode is the last-used mode. I have not implemented wear-leveling for the EEPROM, which is rated for 100k cycles, but it can be done.
It’s coded for 3 modes right now but the mode count is arbitrary and changed by altering 1 number in code. Any added mode PWM values (10-bit) need to be established in code, but the process is simple. The micro I’m using has sufficient RAM for 128 distinct brightness modes.
There’s a built-in 10mS delay between init and turning on the main regulator, which is controlled in software. This allows input capacitors and all reference voltages, including filtered PWM lines, to settle before turning on the light, to avoid erroneous bounces. I’ll probably tune this to the minimum on a per-driver basis.
Technically the regulator-enable function also allows for coded strobe modes but those are dumb and therefore not implemented.
I will wait until I have a functional prototype with a temperature sensor mounted LED-adjacent to worry about overtemp throttling. Depending what kind of control loop must be implemented, that feature may end up using as much code as all the rest combined.
The current unoptimized version (I know there’s some arbitrary code in there) compiles to 174 instructions.
Next step, PCB design.