Setup Example

Real-time Motor and Motion Control with a Raspberry Pi without a real-time OS

Single-board computer (SBC) gained more and more popularity during the last years due its opensource software and the simple hardware. With these SBC it is possible to develop quickly and easily prototype systems or even full products. The standard Linux distributions have no real-time capabilities. For many projects like a digital weather station, this is not crucial. For motion control, on the other hand, it is mandatory to have real-time access for making clean acceleration ramps, position control and closed-loop operation. All of this is possible with motion control ICs from TRINAMIC without needing any real-time operating system on the SBC.

The project below shows how to do precise autonomous cyclic movements with the TMC4361A without any MCU power. The Raspberry Pi 3 is used to set up the needed registers and from there the TMC4361A takes care of the movement. The used system consists besides the Raspberry Pi 3 of a TMC4361A-BOB and a TMC5160-BOB, which is used a plain pre-driver stage, so the internal motion controller is deactivated. The usage of the TRINAMIC’s API – TMC-API – is minimizing the software effort.

The motor will do alternating exactly 5 rotations at 2.5 RPS and 5 rotations at 5 RPS. The switching points are handled by the TMC4361A in hardware. So there is no need for real-time software capabilities. The following steps need to be done to setup the TMC4361A:

  1. Basic configuration of TMC4361A for controlling the TMC5160 family in step/dir mode
  2. Basic configuration of TMC5160 for step/dir mode via cover datagrams
  3. Activation of circular motion, see chapter 8.5.2. of TMC4361A Datasheet
  4. Setting up a one stage shadow register set, see chapter 9.2.1 of TMC4361A Datasheet
  5. Configuring a cyclic pipeline structure, see chapter 9.3.4. and 9.3.5. of TMC4361A Datasheet

Software Preparation

In this tutorial we are using a fresh Raspbian Stretch System (Version November 2017 – Release date 2017-11-29) with the latest updates:

Download and install the bcm2835 library. Note XXX is a placeholder for the latest version. For this guide, version “1.52” was used. In this case, XXX is replaced by “1.52”. You can check the latest version by scrolling to the bottom of the following page: http://www.airspayce.com/mikem/bcm2835/

Create a project folder and download the latest TMC-API. Note X.XX is a placeholder for the latest version. For this guide, version “3.02” was used. In this case, X.XX is replaced by “3.02”. You can check the latest version by scrolling to the bottom of the following page: https://www.trinamic.com/support/software/access-package/

Enable step/dir Mode on TMC5160-BOB

The TMC5160-BOB allows the TMC5160 to use in 2 different modes: With integrated motion controller and in step/dir mode. For controlling the TMC5160 by the TMC4361A the TMC5160 has to be in step/dir. On the TMC5160-BOB this can easily be done by desoldering the R2 and soldering it to R1.

TMC5160-BOB: R1 and R2 are red marked 

Wiring

The wiring is very simple. You will need 18 jumper wires. As a reference, you can use the TMC4361A-BOB_datasheet_Rev1.0.pdf and TMC5160-BOB_datasheet_Rev1.0.pdf.

Raspberry Pi 3 GPIO Header – Source: https://www.element14.com/community/docs/DOC-73950/l/raspberry-pi-3-model-b-gpio-40-pin-block-pinout

Rasbperry Pi to TMC4361A-BOB

Signal Raspberry Pi 3 TMC4361-BOB
VCC_IO 3.3v (1) VCC_IO (1)
GND GND (39) GND (2)
TMC4361A CLK GPIO04 (7) CLK (3)
TMC4361A NRST GPIO15 (10) NRST (4)
SPI Chip select (CS) SPI0 SCLK (23) CSN (5)
SPI CLK SPI0 SCLK (23) SCK (6)
MOSI SPI0 MOSI (19) SDI (7)
MISO SPI0 MISO (21) SDO (8)
TMC4361A-BOB

Rasbperry Pi to TMC5160-BOB

Signal Raspberry Pi 3 TMC5160-BOB
VCC_IO GPIO02 (3) VCC_IO (1)
TMC5160 CLK GPIO14 (8) CLK (8)
TMC5160 DRV_ENN GPIO03 (5) DRV_ENN(9)

TMC4361A-BOB to TMC5160-BOB

Signal TMC4361A TMC5160-BOB
GND GND (2) GND (2)
SPI Chip select (CS) CSN_DRV (18) CSN (3)
SPI CLK SCK_DRV (19) SCK (4)
MOSI SDI_DRV (21) SDI (5)
MISO SDO_DRV (20) SDO (6)
STEP STPOUT (22) REFL (10)
DIR STPDIR (23) REFR (11)
TMC5160-BOB

Raspberry Pi Code

An example code to initialize the TMC5160 is shown below. These files need to be placed in the same project folder as the TMC-API, in this case into ~/TMC_EXAMPLE. First, +3.3V is supplied to VCC_IO, the driver stages are enabled by pulling down DRV_ENN and the internal clock is used by pulling down CLK16. Afterwards, the TMC5160 is initialized and a simple move to position cycle is executed. The sequence will rotate a 200 full stepper motor 10 revolutions clockwise and 10 revolutions counterclockwise – depending on the wiring of the stepper motor. Please refer to the TMC5160 datasheet or the TMCL-IDE as a reference for the different registers.

You can also download the source files directly with your Pi:

 

 

 

 

Compiling and running the code

Use the following command to compile the code.

Now you are able to execute this example.

Be aware that the motor runs as soon as you execute the program.

Related Pages

TMCL-IDE

TMC4361A

TMC4361A-BOB

TMC5160

TMC5160-BOB

TRINAMIC Technology Access Package -TMC-API

www.trinamic.com

Leave a Reply

Your email address will not be published. Required fields are marked *