Today I am posting up version 0.1.4 of the Arduino Alternator Regulator
source code. IT corrects several small bugs, and has one major
change: the expansion of the core alternator regulator engine from a PD**
one to full PID** logic.
** PID: Proportional Integral Derivative
http://en.wikipedia.org/wiki/PID_controller
I had originally only used the rather uncommon PD parameters in the DG
Generator regulator as it was suggested by someone with a strong experience, it
was simpler to implement (there are some odd issues around the I factor), and
it produced good results. However, as the Arduino Alternator Regulator was
deployed with different combinations of alternators and batteries, excess
cycling started to appear. At all times the battery was protected from
over voltage due to the 'load dump' safety checks, but those same load-dump
checks also tended to exasperate the cycle.
I have expanded the controller engine in V0.1.4 of the source code to
implement all three parameters (PID) for voltage, amperage, and wattage
regulation. Which brings up a whole new class of work: Tuning...
Tuning the PID engine is going to take some time, and I hope input from
others. It may be that a common set of tuning parameters cannot be
found to cover all variations of alternators / batteries - and some reduced set
be selected based on DIP switching settings. OR it may be that some type
of run-time self adjustment factor is needed. This is all TBD. For
now, the v0.1.4 release has the original tuning values in it, and I have
entered a 0 for the 'I' factors - disabling that component in the
default. In this way, this release will function as prior releases
have. If there is anyone out there with insight into PID engines, perhaps
they can share?
There are several other small changes / corrections as well.
Including:
- Improved summing logic in
manage_alt(). Prior summing logic for the different regulator
factors (volts, amps, watts, etc..) would allow too large of an increase
in the PWM when one of the factors only wanted a small change.
Example, if Volts decided a +1 was needed, the rest of the regulated
values would often push that up to a +2. New code makes sure the
smallest change is brought forward.
- Sudo-dynamic
rate-of-PWM-chage-cap. There is a hard cap of +2 PWM changes at any
given 100mS sampling period (slowing during the ramp up period). The
new summing logic above effectively reduced that max ROC value as one of the
regulated values gets close to its target. With this, in future
releases I may be able to increase somewhat the max ROC value from +2 to
say +4 or +5 - but want to make that change in combinations with any PID
tuning results.
- int2frac() at would cause 13,998v
to be presented as 13.00 as opposed to 13.99 or 14.00v Corrected
(now will just show 13.99v - no rounding factor)
- DBG; string has been
adjusted - see source code for what it now shows in detail.
- #TESTING mode 'battery' model
enhanced - to allow more realistic simulation modes. See
read_INA226() function.
- Added fixed correction offset
for hardware design issue with Amp shunt level shifter - which caused a
display of 14-17A when the shunt was not connected.
This last issue is a rather tricky one - there is a hardware design fault
around the Amp Shunt level shifter U6 / R22 / R24 that can caused a current to
be falsely reported when it is not present. The problem is reusing the
3.3v rail as a reference point to center + and - current sampling around.
U6 and U2 do a great job of removing common-mode noise, but the problem is R22
/ R24 present a differential divider - and hence the common noise is reduced on
the Vin+ pin of U2, but not the Vin- pin.
This noise gets interpreted as current.
The source of the noise is the LDO 3.3v regulator U1 as it manages voltage
around 3.3v - and reports back from folks using the Arduino Alternator
Regulator match my measurements and seem consistent. And as there are
already several examples of this regulator out there, implementing a hardware
fix might be problematic. As such, v0.1.4 of the source code has a
correcting factor of 522 added to the raw Amp Shunt reading to adjust for this
asymmetrical division of common mode noise via R22 / R24. See 'VERY
BAD!' read_INA226()
Finally. I was able to
at last install this source code into a live alternator aboard Viking Star - so it has had at least
one test run! Over the coming weeks I will be doing more and more test runs, likely refining the software and making changes to the tuning engine.
And a last note: The code is growing. With the above additions I
ended up being over-sized in TESTING + DEBUG mode. So, I disabled ASCII
INPUTS via a check in loop() while in TESTING mode. I may try to look for
code reduction opportunities in the future, but for now take note of this
change. As the tuning firms up some, if it turns out the new 'I' factor is not needed - will pull it from the code to recover some of that code space.