- State machine and control merged to one function
- Load states marked as deprecated, global error flags used instead
- Reduced duplicated code and made load control function easier to read
The bat config calculation did calculate the absolute max voltage
too high, it was doing an unnecessary multiplication.
This triggered an issue in the voltage limit set code, which did not
handle the overflow of the 16bit limit value properly.
Both are fixed now. We limit the limit value to what the ADC is able
to deliver, so that we detect overvoltage for sure, even if the setting
is out of ADC range.
- replaced the lengthy adc value formulas with respective functions
to ease reading
- removed unecessary casts for alert callbacks
- added static to the internal global variables in order to hide them from the
other compilation units
- During overvoltage alerts, only power sources (PWM switch and DC/DC are
switched off), undervoltage only switches load off
- Alert inhibit added to prevent switching off during PWM switch startup
Check for overvoltage/undervoltage conditions after each ADC reading cycle and
trigger alert (stopping DC/DC, PWM switch and load output) if limits exceeded.