HAL-Configuration with Eagle

With this workaround the EMC hardware abstraction (HAL-) layer can be configured with the aid of Eagle CAD Schematics editor.
Since the export script and the library are a workaround for configuring hal-layer, basic knowledge about EAGLE and the hal-components are required.
The library contains only part of the hal components and makes no claim to be complete!
The export script does not check for any errors, so debugging is made by starting emc and checking stdout/stderr-debug-prints


  1. EMC2 (tested with version 2.2.2)
  2. Eagle CAD (tested with version 4.16r1)
  3. HAL-package for eagle (includes library with hal-components and an export-script to generate hal-files)
Current version: updated HAL-package.

Installing hal-package

Just copy the contents of the tarball to your eagle working directories (export-script to ./ulp, library to ./lbr, example script to ./projects).

Special Devices and conventions

Some of the devices have special functions and have to be treated in a certain way.


Eagle's clock pins are always used as functions. Functions can be connected to threads.
These pins are treated in a special way, they should not be connected to other kind of pins.


Pins with a Dot in the schematic (usually a negatived pin) are always connecting parameters.
These pins are treated in a special way, they should not be connected to other kind of pins.

loadrt / loadusr

To add a 'loadrt ...'-line to the script, just place a 'LOADRT'-Device to the schematic. If the order of all of the loadrt/loadusr-lines doesn't matter, just apply a useful name. If it does matter (e.g. 'loardrt probe_parport' has to be executed before 'loadrt hal_parport'), start the name with an index (e.g. '0:trivkins'). The loadrt/loadusr-commands will be written in the order of the indeces to the hal-files. Nothing will happen until now, because the name is not used anymore. Now add a value to that device and enter the complete line to be written to the hal-file - thats it. There are some predefined LOADRT_... - devices in the library that have no real special meaning and are treated as a generic 'LOADRT'-device.


I know of two threads that are running im EMC realtime: BASE-THREAD and SERVO-THREAD (maybe there are more...). If you want to hook functions into a thread you can do this by adding a 'THREAD'-Device to the schematic. Name this instance correctly, the export-script will use the name too hook the functions into this thread.
If the time-slot is important, you can choose between serveral time slots (negative and positive ones). If they are not sufficiant, just edit the device in the library and add some more pins by keeping the naming conventions...


To set a value to a parameter, add a 'PARAMETER'-device to the schematic and give it the desired value (will be written as a string in the configuration, so everything is possible here).




Logic gates and other devices

Just add them, hook the function to a thread and connect the pins the way you want to, they are loaded automatically by the export-script (as long as they are implemented in the export-script!).

Example configuration

martin's configuration

The example script martin_old.sch show the author's configuration of a small desktop-mill controlled over one parallel-port.
Left hand all the realtime-modules that are loaded at the beginning of the hal-configuration are listed. Underneath the two threads are shown. The center shows the default axis-configuration for three axis. To the right the parallel port collects all the signals and routes them to the hardware. All the stuff above the axis configuration is for generating a 'sleep'- and a 'boost'-signal for the axis-drivers. ('Sleep' is used to lower the stepper's current when no motion is commanded. 'Boost' increases the current when at least one stepper starts moving - OK, it should do so, but it doesn't work correct, at least it shows some more possibilities of this export-script...)

Using the hal-package - Troubleshooting

I'll repeat it once again: This is only a workaround, so many bugs and errors may follow...
When starting a new configuration the easiest way is to copy an older one.
Export is done by executing the user language program 'hal-write.ulp'. Maybe you have a look at the source code and replace the export path to your needs.
It is very important to consider some rules and naming conventions:

Contact me for feedback or questions.
Enjoy the bugs