Friday, November 23, 2012

Posted 1st cut Arduino / Alternator software

This evening I posted the 1st pre-draft cut of the Arduino software.  This software is largely completed in terms of function, but it is heavily untested.  Mostly because I do not have the hardware PCB boards back yet!

However, I have been testing as I can on the Arduino Uno.   You will notice the #define DEBUG early in the code, this is used by compiler directives to change some of the behaviour to facilite this limited testing.  Example:  Enabling the Serial port, turning on the pull-up resister on the Analog input port used for local switches (the actual hardware has its own pull-up).

I will likely be taking a break over the next couple of weeks, and then will take this back up to look for bugs, see if I can increase readability of the code, etc.

And on readability, am making no claims this is fabulous code.  It is in many ways heavy handed . . .  Perhaps will improve that over time as well.

The basics of the software is the main loop which will check the current time against prior stored LONG time variables to see if sufficient time has passed to warrant doing a task.  Example, we update the LCD every 1/2 second or so, while checking the voltage/current sensors several items a second.  All these times are controlled via #define variables in the beginning of the program.

There are two 'escapes' to this main loop which have mini-loops in them:  Start and Stop of the Kubota.  Rather then clog up the main loop with state checks, I decided to just let each of these functions grab a-hold of the looping them selves.  As such you will see Keyboard queries and LCD updates scattered throughout the Start and Stop functions.

The Display function is only ruffed in, I need to tidy up the screens.  Do things like turn on and off the LCD back-lighting  etc.  Also need to add the Buzzer when the unit is faulted.

You will also notice two modified libraries:  I2Cx, and LCDI2cwx.  The I2Cx lib is an extension of the fault resilient I2C driver work done by Wayne Trichsess (Link Here) where he improved over the default wire lib to enable the Arduino to recover from I2C faults.  This works as I tested both the standard Wire lib and his and was able to easily make the wire lib hang by introducing hardware noise into the SCL line.  (I was also able to do this with Wayne's lib until I discovered the I2C.TimeOut()  function!   His lib defaults to 0, which disables any fault error handing).   My modification to his work was to add additional I2C.write() calls with different number of parameters.  I know I could have used his *byte function  but that seemed too much work.

The LCDI2cwx is a modification of the default LCDI2cw driver to use Wayne s new underlying lib as opposed to wire.

If you are so inclined, have fun!  And comments are always welcome.

No comments:

Post a Comment