OK, several small changes and this is where I’m at now: v009.c
It’s still definitely not right.
- I’m able to adjust the output PWM with the pot, but I don’t think I’m getting 100% duty cycle even though the voltage on the input pin is the same as Vcc. (I did not check duty cycle with a scope though).
- LVP is definitely not working correctly, but so far it has never turned the light off in any version. The best I ever got was around 10 flashes and then 100% duty cycle and unresponsive to the brightness pot. Now….
- Right now I’ve got some constant pulsing going on, but that wasn’t happening until the latest version… I think.
There are a lot of things I want to tweak, but none of them should be causing these issues… in intermediate versions it felt almost like PB2 was floating, but of course it was not - I checked multiple times with a DMM.
I’m starting to feel like I’m going backwards. I understand better than ever what all this stuff is supposed to be doing, but less than ever why it’s actually doing what it’s doing. It’s all hacked up copy-paste stuff, so maybe significant re-writes would help. In the context of a flashlight where the brightness is controlled by a potentiometer none of the original battery monitoring code makes a ton of sense. I think removing it and starting with a clean slate may be the smart move now.
I guess I’d better disable voltage monitoring again and test to see whether I get full duty cycle with that disabled. Either way the answer is still probably to remove all voltage monitoring code, troubleshoot any remaining problems, then add voltage monitoring back in.