Esduino Master Demo

Attachment
[file] FlscMasterCW.zip
Esduino FLSC Master project built with the Special Edition of CodeWarrior HCS12(X) V5.1

This project is an example embedded master program that controls a single FLSC module + LMD18200 IO board + DC brushed servo motor combination.  The Esduino12 is an inexpensive Arduino-like board sold by Technological Arts based on the Freescale 9S12C32 mcu. The attached zip file is a CodeWarrior IDE project written in the C programming language.  Users are encouraged to use the code as a starting point for their own custom implementation.  Even if the user does not intend to control servo controllers sold on this site the project will be of interest to those who want a non-trivial introduction to the 9S12.  The software is provided as per the MIT license (use any way you wish but the copyright and license portion of the header must not change).

The Esduino was an obvious chioice as my first example embedded master because the integrated CAN peripheral is almost identical to one in the FLSC module mcu and because the hardware comes with the support of Technological Arts.  In addition, the CodeWarrior-SerMon combination is hard to beat because it is free and works very well (my apologies go out to non-Windows users - it seems that most embedded engineering tools run only on Windows).  Note that the Esduino hardware is assumed to include the USB2MCU module for communication with SerMon.

The following pages describeIDE setup, project build, hardware and program details.

CodeWarrior IDE Setup

The "Special Edition" of the CodeWarrior Development Studio for HCS12(X) Microcontrollers is a download from Freescale that is free of cost for the full flash size of the C32 mcu (Windows OS required).  The IDE is a complete debugging environment that works in combination with various types of debugging hardware as well as with SerMon, the monitor/bootloader firmware that comes preloaded on the Esduino.  No debug pod is necessary.  You can step through each instruction of the program to follow program flow and inspect memory/register values.  The Arduino IDE cannot do this!  Even AVR Studio requires the use of extra hardware for Arduino debugging.

After downloading and installing the "Special Edition" version of CodeWarrior for HCS12(X), download the project archive from the previous page and unzip to any folder (ie: c:\dev).  Inside the "FLSCMasterCW" directory, double click on "flscmaster.mcp" to open the project in the CodeWarrior IDE.  The tree on the left side lists the files of the project.  Double clicking on a file will open it inside the editor window on the right side of the IDE.

Clicking on the "Make" icon will build the project and update the output file that can be uploaded to the Esduino flash memory.  As shown in the image, warnings are displayed but they can be safely ignored for this build.

IDE build image

Hardware Setup and Programming

Build the Esduino CAN shield from the bare board available from this site or from scratch using an Arduino proto-board with point to point wiring.  The schematic and BOM are available from the product page.

Set jumpers on the Esduino board as follows before joining it to the CAN Shield:
Installation of FTDI drivers is required on the host computer before it can connect with the Esduino via USB.  The Technological Arts website supplies the instructions and driver software.

Connect the Esduino (with SW1 at "LOAD") to the host computer with a mini-b USB cable.  Windows may not recognize the Esduino as a USB Serial Port when it is connected for the very first time, even after the FTDI drivers are loaded.  If prompted by Windows to select a driver, manually select the direcctory where the FTDI drivers reside.  After the Esduino is recognized as a USB serial port It is likely that you will have to go into Device Manager to change the comport number to COM2 so that CodeWarrior can detect SerMon.  The screen capture below shows the steps necessary to navigate within Windows 7.


(view larger image)

When the Esduino USB connection has been properly established, open the CodeWarrior project, build without errors and click on the "Debug" button.  This will open the debug software which will connect with the SerMon firmware of the Esduino (provided if it has been powered up with SW1 set to "LOAD").  By default the connection will automatically erase any flash contents (the monitor itself is protected against erasure), load the S19 file of the project into the mcu flash and load the debug symbols to into the debugger software to allow source debugging.  Execution of the program will begin after clicking on the start button (green arrow) or by pressing the F5 key.  Note that the 9S12 flash memory can be reburned many thousands of times without issue.  I date back to a time when this wasn't true and so I don't like reprogramming when it isn't necessary.

To set a breakpoint in the IDE, reset the target by clicking on the reset icon, click in the "Source" window of the debugger then click on the "source" menu item and then on the "Open Source File..." menu item.  A list of the source files will appear to select from.  The selected file will appear in the "Source" window.  Use the mouse to locate the line where a breakpoint is to be set and use the right mouse button to open a context menu from which the breakpoint item is selected.  Restart the program.  If it encounters the breakpoint, execution will be stopped and all registers and memory are available for inspection.  The program can resume normal execution with F5 or be stepped forward with F10 (step over functions) or F11 (step into functions).  There are a limited number of breakpoints available so it is normal to deactivate/delete these control points as one drills down into the code while debugging.

Now that the program resides in the mcu flash memory, it will automatically execute upon reset when SW1 is in the "RUN" position.  If for some reason it does not start with SW1 set to "RUN", then a 10K external pullup resistor might need to be applied to pin PS0 (JB4 pin 5).

FLSCMaster Program Details

The project source code is a sample C programming language implementation of an embedded master based on a mcu with a small memory model without threading or multi-tasking.  The purpose of the application is to provide example code for embedded engineers who wish to build customized servo control systems using the FLSC module.  In particular I wanted the project to provide a realistic limit detection regime, an important part of almost all automated mechanical systems.  I crafted the sequence of limits in a way that I think will be easy for users to modify for their own particular arrangement.  The finer details of the program are documented by the internal comments within the code itself.

The program controls only one FLSC module and thus does not demonstrate coordinated multi axis motion.  In short, such coordination is easily achieved by the simply addressing the motion control functions to the respective slave addresses.  What is less simple is the requirement for the master to compute the trajectory for each axis to produce coordinated motion.  These computations are outside the scope of this demo project.

Not every feature of the FLSC is exercised by the program, notably the fuzzy controls, however the low level driver (flsc_l.c) is completely implemented.  Addition of missing functionality is a matter of writing high level driver functions to the unused portions of flsc_l.c.

Tuning of the fuzzy rules, memberhip functions and output singleton for the FLSC module  is currently only possible through the use of the USB to CAN Gateway in combination with the test application.  Once the tuning process with the gateway-test app is complete, the fuzzy control settings can be saved to the filesystem of the FLSC module so that the embedded system will not need to consider the fuzzy control features.

The addition of the LCD and scroll buttons was intended to provide program feedback and debug info via the ASSERT macro.  I could have used the serial port to dump such information but unfortuately the SerMon monitor program has control of the SCI interrupt which makes the construction of a proper interrupt driven serial driver impossible.  I have refactored SerMon to address this issue but it isn't obviously an official version.  The demo works with the stock version of SerMon.  If anyone wants my version I'll send them the CW project.  You will need pod hardware to replace/update SerMon.

The source will compile with the Imagecraft compiler if the preprocessor define that sets the compiler in the all.h file is altered, however, that compiler is not free for the size of the output binary.  If the output were to grow beyond the 32K limit of CodeWarrior's Special Edition, the Imagecraft compiler becomes the less expensive tool, even with the addition of the NoICE debugger and debug pod hardware.  If anyone wants to contribute a GNU port I'll gladly link to it.