Tuesday, November 10, 2015

v0.1.7 source released

Today I posted v0.1.7 of the Arudino Alternator Regulator source code, look under the SOURCE resource tab above.

This release is based largely on field feedback (thank you A-P) and is able to better 'regulate' the temperature of an alternator.  It has two changes in it:

    1) Bug Fix - Prevent any PWM increase if the Alt is at (>=)  its target temperature.
                       Prior would block PWM  increases only when the alt was over temp. (>)
     2) Refinement - Increased gain of PID tuning for Alt Temperature.
              #define KpPWM_TA_SENSITIVITY                0.500      
              #define KdPWM_TA                                        0.750
                ( Was:  0.200 / 0.500  )

The old code 'worked', but tended to allow the alternator to overshoot its upper temperature limit and ultimately triggering an over-temperature pull-back.   With the above changes we can now expect to see a more stable and smooth regulation around alternator temperature when needed.

I want to thank A-P for his live field feedback on this area.  Having feedback from a wide range of installations helps this project tremendously.

As kind of a review, the Arduino Alternator Regulator actually has 4 regulation points (vs. the 1 or perhaps 2 of more common regulators).
  • Battery Voltage - most all regulators do this :-)
  • Battery Current
  • System Wattage / Engine load
  • Alternator Temperature - some 'advanced' regulators do this as well

Each of these 4 regulation points along with other traps and system monitors (e.g., battery temperature, RPMs, etc) can have an effect on how hard the alternator is driven.  Alternator Temperature can come up in a cramped engine space, and to be honest if an install is operating under this mode one should perhaps look at the overall installation:  Perhaps the alternator is too small (or overrated, aka "Too Much Marketing" put into it).  And/or there is a significant cooling issue in the engine room.   But in any case - rest assured, the Arduino Alternator Regulator will manage things as best as can be done given each installation.

Oh, one more change:  I am now using notepad++ as my default editor.  One of its features is the ability to automatically replace tabs with spaces.   And I have turned that on.  Prior source was edited with a tab spacing = 8, and I know many folks use spacing = 4.  By just using spaces the code should 'look good' no matter which editor you are using.

Friday, September 11, 2015

VERY ROUGH - NMEA-2000 bridge source posted

Over the past couple of days I have put together a VERY ROUGH NMEA-2000 bridge, see source code under above resource link (and make sure to copy down the needed libs from their resource tab as well).

This bridge is designed to run on an Arduino DUE connecting to the Serial ports on one or two Arduino Alternator Regulator.  It will receive ASCII strings via Serial 1, and Serial 2 (up to two regulators can be monitored), parse the received data, and place them into a local data structure for further use.

The 2nd part of the bridge will formulate a limited number of NMEA-2000 packets from this received/parsed data and send it out via the CAN0 port. It leverages work done by:
      Collin Kidder (collin80)  https://github.com/collin80/due_can
      Timo Lappalainen (ttlappalainen)  https://github.com/ttlappalainen

For now I have extended Timo's libs to include new PGNs, so make sure to use the libs from the resource tab above.  Once things are a bit proven I will submit the changes back to Timo for inclusion in the main source.

A final capability of the software is to self-generate simulated ASCII strings.  By including the current Arduino Alternator Regulator source and running it in TESTING mode ASCII strings are made available on Serial3 - just use jumpers to connect the Tx3 back to Rx1 and/or Rx2 for Bench testing.

Speaking of proving.  I do not have at this time sufficient hardware to do complete validation of this code.  Specially, I am not at this time able to receive and verify the NMEA-2000 packets.  (I have been able to validate the ASCII string receiving / parsing is working well).  I do have some additional hardware on order, but do not expect to be able to get access to it for a month or two.  (Life on the Float)

I am also a bit underwhelmed on the level of information available within the NMEA-2000 spec.  This source makes use of two PGNs:
  •  PNG:127506 DC Detailed Status
  •  PNG:127508 Battery Status 
One task is to review the PGNs populated and settle on the appropriate ones.

OK, this is a very very rough effort at this point.  And work is still needed (hence the 0.0.0 revision). But I know a few folks have expressed interest in this, and I am curious to see how it works out.  With regard to further proofing / refinements I would like to suggest we utilize the Google group Emailing list: https://groups.google.com/forum/#!forum/smart-alt    That way all folks interested can participate.

 OK, this will be interesting - and perhaps a small start to a proper integrated CAN  regulator project.

Saturday, August 22, 2015

NMEA-2000 bridge

A few people have asked about connecting an Arduino Alternator Regulator to the NMEA-2000 bus - just to report out status.   This morning I spent some time googling to see what was out there, and think there can be a rather simple bridge built based off of an Arduino Due.

Using the Due has a couple of advantages vs. using an Arduino + CAN sheild.  The 1st is perhaps cost - Even overseas, a Uno + a sheild comes in at about the same price as a Due.  Though it is true one will still need to add a transceiver to the Due.  But another advantage is the Due is a 3.3v device - so no 'logic level' conversion will be needed.  It also has a built in CAN controller, with available libs to support it.  And there is even a +5v source that can be used with the CAN transceiver.  And it even has several serial ports, so would be able to act as a bridge for more than one regulator.

Taking in the ASCII status strings from the regulator, parsing them and translating them into some NMEA-2000 packages looks to be a simple task, and I even found a couple of sample sketches that goes a long ways towards that goal:




being a few links.

I have a Due on hand, perhaps can look into making up a simple bridge - or if anyone else wants a go at it, let me know and will make sure to link it in!

Tuesday, July 7, 2015

Hint during installation - remove the old stuff!

This past week I received a hint that I wanted to pass on:  when installing the new Smart Alternator
Regulator make sure to FULLY remove any of the old 'stuff'' attached to the alternator that might have been needed by your old regulator.  Things like boot-strap diodes / resistors (including Dash lamps) - make connections instead as noted in the documentation.    

And be on the look out for hidden resistors.  One person found a large 270 ohm 5W resistor attached from the old D+ terminal (no longer used) to GND.  Originally intended to help drive the dash lamp and also provide a minimum load to keep the alternator driven tach running, this extra phantom load played havoc with the Smart Alternator Regulators attempt to stabilize things with its own tachometer mode turned on.

So, pull out the extra stuff - you have been warned!

Release of Source Code v0.1.6

Version 0.1.6 of the source code has been posted under the resource tab above.  There are several small changes - mostly refinements with the TACH mode of operation as well as integration with an external BMS typically used in LiFeP04 batteries.  The accompanying documentation has also been updated to reflect these changes, again under the resource tab above and now release 0.1.3

Here is a summary of the changes:
  • Corrected fatal coding error in withdrawn release v0.1.5 - manage_alt();  (Uninitialized variable: enteredMills)
  • Corrected ASCII error in CPE; string, not reporting float_to_float values correctly.
  • Improved feature_in() handling to retain last know state while checking for debouncing.
  • Much improved Tach mode code
    • Setting tach PWM via $CST: command will become effective immediately, even during engine warm-up hold off period.
    • Tach mode will hold min PWM during transition into Float, allowing tach to continue to run when initially entering float mode.
    • Reduced MAX_TACH_PWM from 100 to 75, to better protect battery from too high a PWM floor.
  • Added new Amp-Ah based exit criteria for Float and Post-float
  • Added Alternator state: FORCED_FLOAT mode - enabled by feature-in port with CPE#8 for use with external BMS system
    • AST; modes mode numbers updated to include new alternator mode FORCED_FLOAT
  • Changed SST; status to include version number as opposed to compile date/time.
  • Increased NTC usable temperature range, now reporting -54f to 300f
  • Shortened engine warm-up hold off period from 60 seconds to 30 seconds
  • Dash lamp now illuminated during engine warm-up hold off period, to emulate typical 'lamp test' behavior during startup
Many of these refinements came about through the hard work of Antti-Pekka Virjonen who has deployed the Smart Alternator Regulator with a nice new LiFeYPO4 battery in conjunction with a BMS.  I really appreciate the feedback from others, and the help of Antti-Pekka in helping me.  We not only made several improvements to the tach mode of operation, but also refined the function of the feature-in port when used in conjunction with an external BMS.

And I am glad to report the PID tuning worked spot-on with his system!  No changes needed at all!  I can see where perhaps adding in a little 'I' might tighten regulation up some, but as is the system held target  voltage with 25mV of the goal during trial runs.

Please make sure to download both the new documentation as well as the source and note the few changes in status strings (SST and AST).

Thank you again A-P, and happy sailing this summer!

Saturday, June 27, 2015

Still here - how is YOUR summer?

Just a quick note, no have not gone back to the future :-)    But have been kind of distracted with maintenance needed on our boat after it sat unattended for a full year.

Even with that, have been working with someone who is just about to deploy a nice LiFeP04 system - very high tech.  And with that we are refining some of the approaches used to integrate the regulator and other devices, specifically the BMS.

I do have a new revision of source in the works, but am holding off releasing it until we get some hours on the LiFeP04 system.   If anyone is interested in joining the conversation, or is having issues of their own with the current source out there - drop me a line.


Wednesday, March 4, 2015

Release of Source Code v0.1.5


Today I posted source version 0.1.5 for the Arduino Alternator Regulator.  See the file under the Source resource tab at the top.  There are really two major changes with this source:

1) It targets Arduino IDE 1.6.0 - now the 'official' released IDE from Arduino.cc
2) It has refined PID tuning based on users feedback as well as testing on Viking Star.

See the prior post for some more details about the new Arduino IDE, along with needed support files to enable the 3.3v bootloader.   I also needed to make some small syntax changes in the source to reflect subtle changes to the Arduino IDE around PROGMEM.  Going forward future released will be tested with the mainstream 1.6.0 and after release of the Arduino IDE code.

PID tuning.  The past weeks I have had a chance to try different combinations of PID tuning on Viking Star, mainly using our DC generator (Which shares a common source base in the manage_alt() function).  That, combined with feedback I have received from a few uses (THANK YOU so much!) I have what I believe is 'better but not final' PID values.  They are a bit less twitchy when deployed in a system that has a larger alternator vs. battery size - like many AGM batteries, or perhaps LiFeP04 systems.  I do not believe these are the final values, and in fact I am still only using the P&D values, the new I is disabled.  But I do believe they are better, and am looking forward to gaining feedback on them form others.

The PID tuning is perhaps the greatest challenge facing this project today.  Most all other functions are rather stable.  But as more experience is gained with different combinations of alternators and batteries, I can expect there will be additional insights.  Ideally we can find a common set of PID values what works well in all cases, but in the end it may be that some type of sampling / real-time adjustment will be needed.   But that is down the road even more.

Supporting release 1.6.0 of the Arduino IDE

Arduino has released a major update to their toolset, now version 1.6.0.  It includes better support for the ARM type Arduino CPUs and is now the 'primary' release stream.  Of impact to the Arduino Alternator Regulator is this release also has updated the GCC compiler - resulting in about a 5% reduction in code size!

But they have also changed some of the file structures with regards to enabling custom bootloaders.

If you look under the Arduino Libs resource tab above you will see a new folder to support the Arduino IDE 1.6.0 with a fixed Optiboot to allow the watchdog to function (as opposed to totally wedge the system using the as-included 8Mhz bootloader in the Arduino IDE).  Just follow install the new Arduino IDE release 1.6.0, copy down the files from the resource tab above and follow the instructions in the readme.txt file to allow the newest Arduino development environment to support the improved bootloader for 8Mhz operating of an ATmega328p cpu.

Friday, February 13, 2015

Released v0.1.4 of Source Code

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.

Sunday, February 1, 2015

Refreshed Optiboot bootloader

I have been having a few reliability issues with the optiboot source code included in the Arduino IDE - which I used to compile a special bootloader for the regulator project:

So today I refreshed the complied bootloader using the latest source code from optiboot source repository: https://code.google.com/p/optiboot/

The resulting .HEX file is found under the Ardino Libs tab above, look for the 'SmartRegBoot' subdirectory - and follow the instructions in the blog link at the beginning of this post.

This refreshed optiboot still is configured for 8Mhz, 57600, and no-LED flashing.  With my limited trials, I have found it to be a bit more stable...