"... and no one shall work for money, and no one shall work for fame; But each for the joy of the working, and each, in his separate star, shall draw the thing as he sees it, for the god of things as they are"

-Kipling

 

Tilo:
Client-Server Stepper Motor Control on the Beaglebone Black

Summary

The purpose of this project is to build a Client-Server application which can enable the Beaglebone Black to control the pulse and direction signals for up to six stepper motors.

A Windows based C# application (TiloWinServer) acts as a controller to send the frequency and direction information to a C# Mono based client (TiloClient) running on the Beaglebone Black. Both the Server and the client share a common code library (TiloCommon).

Since the Linux operating systems (in general) offered for the Beaglebone Black are not designed for realtime operations, one of the Programmable Realtime Units (PRU1) on the Beaglebone Black is used to control the stepper motor step and direction signals. This means the train of pulses to the stepper motors is both continuous, consistent and not affected by the operating system swapping processes in and out of memory.

The flow of information proceeds from the TiloWinServer via TCP/IP to the TiloClient which then hands it off to a program running in the PRU1 which sets the direction signals and forms the pulses at the appropriate frequency. The information is transmitted from the Server to the Client (and back) via an instantiated C# object. If your interest is primarily in the ability to send information via TCP/IP wrapped in an object container, then you should probably have a look at the RemCon project - this project is specifically designed to demonstrate that functionality. The Client/Server aspect of the Tilo project is directly derived from the RemCon project.

The program running in the PRU1 (PRU1_StepperIO.p) is a PASM Assembly language program. It is designed to produce consistently timed pulse frequencies irregardless of how many other steppers are running or if they are enabled or disabled while others are running. It does this by setting up "blocks" for each stepper that take an equal number of steps (10) on every branch. Thus, if the motor is disabled the block takes 10 steps, if the motor is enabled and sending pulses it takes 10 steps. Even the special circumstances during the transition of the output pin from low to high (or vice-versa) also take 10 steps. This makes the output very stable with no "short" or "long" pulses while other motors activate or de-activate. Quite high frequencies (around 1.5MHz) are possible and significantly higher frequencies would be possible if the number of supported steppers was reduced and/or other optimizations undertaken.

The PASM Assembler is available online as C source and a pre-compiled version can be obtained at the following address https://github.com/OfItselfSo/PASM_Assembler. The TiloClient has a post build step that will compile the PRU1_StepperIO.p file. You will need to obtain the PASM Assembler or you can just ignore the error and use the compiled version of PRU1_StepperIO.p which ships with the source code.

The PRU1 outputs its signals on the following pins on the P8 header of the Beaglebone Black

STEP0_OUTPUTREG P8_45 // the pin we toggle to set the state
STEP0_DIRREG    P8_46 // the pin we toggle to set the direction
STEP1_OUTPUTREG P8_43 // the pin we toggle to set the state
STEP1_DIRREG    P8_44 // the pin we toggle to set the direction
STEP2_OUTPUTREG P8_41 // the pin we toggle to set the state
STEP2_DIRREG    P8_42 // the pin we toggle to set the direction
STEP3_OUTPUTREG P8_39 // the pin we toggle to set the state
STEP3_DIRREG    P8_40 // the pin we toggle to set the direction
STEP4_OUTPUTREG P8_29 // the pin we toggle to set the state
STEP4_DIRREG    P8_30 // the pin we toggle to set the direction
STEP5_OUTPUTREG P8_27 // the pin we toggle to set the state
STEP5_DIRREG    P8_28 // the pin we toggle to set the direction
It should be noted that the pins used by the PRU1 conflict with those used by the HDMI video and thus the Beaglebone Black must run headless in order to output the signals. In the authors test system the eMMC memory was also disabled.

A suitable Device Tree Overlay with the appropriate PinMux configuration is included in the source code of the project. A help page which provides advice on implementing the overlay is also available, please see the Beaglebone Black And Device Tree Overlays page.

Using the Tilo Project

The process of getting the Tilo Project software operational has numerous pre-requisites.

  1. Ensure that you can connect to the Beaglebone Black from the Windows box which will function as the server.
  2. Copy the TiloClient code to the Beaglebone Black and compile it. You will need mono installed.
  3. The TiloClient software is written in C# and uses the BBBCSIO library to launch the PASM executable in PRU1.
  4. You will probably need to enable the UIO drivers on the Beaglebone Black to get the BBBCSIO software to interact with the PRU correctly.
  5. You will need to adjust the TCP/IP address in the TiloCommon source in order for the Server and Client to connect properly. This means you will need to compile both applications.
  6. It does not matter which is launched first, once both the TiloClient and TiloWinServer are operational they will find each other and connect.
  7. As soon as the connection is made, the TiloWinServer application will send over the instructions for the stepper motors. By default all steppers are disabled.
  8. The TiloWinServer presents a GUI interface which enables the user to change the enabled state of each of the six steppers and to set the pulse frequency and direction signals. This can be done in response to every change or the Auto-Send mode can be turned off and the changes sent en-mass by pressing the Force Send Data button. The pulse frequency information can be specified in Hertz or in delay cycles which enables the output to be calibrated.
  9. Closing either the TiloWinServer or the TiloClient will halt the program running in the PRU and shut things down properly.

The Sample Code

The Tilo Sample Applications are open source and released under the MIT License. You can download, clone or fork the Tilo Sample Projects at the following address:

https://github.com/OfItselfSo/Tilo

Screenshots

The example screenshot below is the main form of the TiloWinServer sample application after it has sent several messages to the TiloClient.

License

The contents of this web page are provided "as is" without any warranty of any kind and without any claim to accuracy. Please be aware that the information provided may be out-of-date, incomplete, erroneous or simply unsuitable for your purposes. Any use you make of the information is entirely at your discretion and any consequences of that use are entirely your responsibility. All source code is provided under the terms of the MIT License.