Tuesday, August 5, 2014

Capturing log data for assessment

The Arduino Alternator Regulator will output a stream of ASCII data via the service port providing details on its current operation.  I have used these dumps to help improve the PID engine tuning as well as resolve issues.  In this Blog post I want to describe one way to capture log data into a .txt file, and perhaps ask that folks send in a few of these so I can improve the base code.

To capture the ASCII stream, you will need to do the following:
  1. Attach a USB <--> TTL adapter to the Service Port
  2. Open up the Arduino IDE
  3. Select the serial port used by the USB <--. TTL adapter in Step #1 via Tools/Serial Port
  4. Make sure the correct Board type is selected via Tools/Board (Smart Regulator.. for the 3.3v regulator)
  5. Open the Controller 'sketch' (source code).
  6. Un-comment the line #define DEBUG  (remove the two // at the start of the line)
    • This will cause an extra set of debug information to be sent to the serial port.
  7. Consider changing   "#define   SDM_SENSITIVITY    10"  in the source code from 10 to a smaller number, especially if looking at load-dumps, or some odd issue.  This #define controls how may times through manage_alt() before a debug string is sent out.  Setting it to 1 gives the most data, and the largest files.. 
    • 10 was chosen to allow operation via the Bluetooth at 9600 baud.
    • If you reduce this number to say 1 (which is needed many times when debugging), you should turn off the Bluetooth module, and then change '#define  SYSTEM_BAUD'    from 9600 to      115200 and run the serial terminal at that speed.
  8. Upload the new sketch.



Example debug output.

You now have an option.  You can remain in the Arduino IDE and open the Terminal window to see the ASCII data - I find unclicking 'auto scroll' helps make things run a bit smoother.  Then after some amount of data is there, so a copy-n-paste into a standard text editor (ala, notepad), finally saving the file in .TXT form.

Oh you can use a 3rd party terminal program.  Myself, I like to use PuTTY as it is simple,  reliable, fast, and you can enable it to automatically capture the .txt file.  To use PuTTY take note which serial port is being used by the Arduino IDE to communicate with your controller (Step #3).  Then download PuTTY using the following link:   http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Once installed, open PuTTY and make the following changes:
  • On the opening screen (Session screen), enter the Serial port and Speed from step #3 above.  Click the 'Serial' button.
  • On the Session/Logging screen, click the 'Printable output' button and enter a log filename.  Each time you run PuTTY data will be captured into this log file.
  • On the Window screen, change the columns to something large, like 400.
    • Not really needed, the log file will be OK w/o this change. 
    • Just makes the visible screen look a little nicer.
  • Then go back to the Sessions screen and click the 'default setting' profile and press the Save button.
Now each time you start PuTTY it will open to the correct port, and automatically start saving a data log.  Press the 'Open' button on the bottom to connect to the controller and start a data capture session.  When finished, just close the window and the log file will be saved.  Rename this to something meaningful, and perhaps edit using notepad to add in some details about the captured run, ala alternator / engine / battery size.  Any unusual event - like a washer/dryer running during Float mode, other charging sources.  Anything you think might be relevant.

If you would then Email it to me, I can use it to help look for ways to improve the code.

You can search for 'DBG:' in the source code to get an idea what data is being sent out.  And if you do have any issues with the regulator, make sure to set the sensitivity to 1 and capture all the data.  Note that the 1st number sent out is a time mark, so in the preamble it would be good to comment on what you see going wrong, and referencing to the approx timestamp if you can.

And when finished you can reload the firmware with the #define DEBUG commented out - disabling the ASCII strings.  Make sure to restore '#define  SYSTEM_BAUD' if you changed it.