Trinamic's TMC5160-BOB setup

Driving Stepper Motors with the new TMC5160 by using TRINAMIC’s API on a Raspberry Pi

This start-up guide explains how to connect your Raspberry Pi 3 to the TMC5160-BOB – the breakout board of the brand new TMC5160. We’ll be using the internal Motion Controller and +3V3 logic supply for the TMC5160. The wiring will be limited to the basic functionality to communicate via SPI. The usage of the TRINAMIC’s API – TMC-API – is minimizing the software effort.

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/

Wiring

The wiring is very simple. You will need 8 jumper wires. As a reference you can use the TMC5160-BOB_datasheet_Rev1.0.pdf. You will find the signals that are on each pin.

Signal Raspberry Pi 3 TMC5160-BOB
VCC_IO GPIO02 (3) VCC_IO (1)
GND GND (39) GND (2)
SPI Chip select (CS) SPI0 CE0 N (24) CSN (3)
SPI CLK SPI0 SCLK (23) SCK (4)
MOSI SPI0 MOSI (19) SDI (5)
MISO SPI0 MISO (21) SDO (6)
TMC5160 CLK GPIO04 (7) CLK (8)
TMC5160 DRV_ENN GPIO03 (5) DRV_ENN (9)
TMC5160-BOB

 

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

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

TMC5160

TMC5160-BOB

TRINAMIC Technology Access Package -TMC-API

www.trinamic.com

34 Comments

  • Radek

    Hello Mario,
    Very nice example.
    Will this API compile on Beaglebone or will work with Arduino either?
    How about reading encoder pulses by this BOB module – any code is available in API?
    And last question: how 5160-BOB is comparable to 2660-BOB – I mean about reading encoder pulses for close loop and also about powering stepper with 2.8A/phase?
    Best regards

  • Mario Nolten

    Hi Radek,
    yes, you can use this API also on a Beaglebone. You probably need to adapt the SPI function for the Beaglebone. On an Arduino it is not so easy to use. The Arduino IDE does not allow to have a folder structure as we have in our API.
    For reading encoder pulses, you can directly connect the encoder to the TMC5160-BOB and read out the pulses from TMC5160_XENC. By setting the prescaler it shows directly the encoder position in microstep.
    The TMC2660-BOB is a bit different. The TMC2660 is a plain driver IC (without integrated motion controller as the TMC5160 has) so you need to apply step/dir pulses to drive the motor and the encoder has to be connected directly to the MCU. For this we have no API code for a Raspberry Pi or Beaglebone, since it is for both crucial to have a realtime OS.
    Best regards,
    Mario

  • Radek

    Mario,
    Thank you for valuable information.
    This is a very interesting product. I needed some time to break through the documentation. At the beginning I will try to run in mode 2 with an external application and without collecting the signal from the encoder. Then I will try mode 1 and encoder. One more question: if two motion controllers are used for controlling axes X/Y (amateur laser cutter), then both of them must be addressed separately or is there some form of communication between them and the code can be simplified? Will I find the answer to this problem in the API or do I have to implement it myself? In addition, is there any documentation how to electrically connect several axes in such a system using 5160 so that the motion controllers cooperate?
    Best regards
    Radek

  • Mario Nolten

    Radek,
    for controlling multiple axis / ICs, each one of them has to be addressed seperately. The API is currently working with 1 motor but it should be pretty easy to extend it to 2 or 3 axis. You should be able to reuse most of the code for the additional axis. The API is in continous progress and multiple axis control is on the agenda.
    Best regards,
    Mario

  • Radek

    Mario,
    I will try to do it then. I would like to make SPI communication using PRU on BBB. I will see how it will go. I do not know just what I can gain from SPI communication. Step/Dir is working very nice at PRU at this moment with BeagleG code from Henner Zeller for example or Replicape project (they using TMC2100 on a cape for BBB -they also use SPI but only for some chipset configuration). Is the use of SPI can improve something here or is it better to stay at TMC2660 with step/dir commands and save some bucks? What do you think?
    Best regards
    Radek

  • Mario Nolten

    Radek,
    using step/dir is probably more straight forward since the firmware is already written for this. For using the internal motion controller you would need to adapt it. BTW: You can also use the TMC5160 in step/dir to have all benefits like higher currents, stealthChop2™, differential current sensing, etc. In this case you only need the SPI to configure the run current, chopping mode (spreadCycle™ or stealthChop2™).
    Best regards,
    Mario

  • Radek

    Mario,
    Yes, and this is the reason why I will probably stay with TMC5160. It has all the newest features compacted into one small chip, so for me is very versatile.
    Thank you again and I let you know about the effects.
    Either way, good job with this API.
    Best regards and have a good weekend.
    Radek

  • Marco

    Mistake: In the table Signal – Raspberry Pi 3 – TMC5160-BOB
    SPI Chip select (CS) should be pin 24 on the Raspberry Pi

  • Mario Nolten

    Marco, thanks for the comment.
    It is corrected now.

  • Richard

    Hi,
    I’m interested in using the TMC5160 for CNC electronics, the dcStep feature is very interesting from a cnc milling perspective when milling through materials like metal.
    However dcStep appears to be an open loop system and I don’t think you can use an encoder at the same time.

    If someone wanted to use the motion control system to vary the speed based on the load (dcStep)
    keep multiple axis such as an x and y in sync as the speed varies (I think DCIn / DCO)
    but also use a closed loop encoder to verify the position
    which would be the best way to do this?

    I’m wondering if several TMC5160’s with the DCIN / DCO pins hooked up to keep things in sync with dcStep
    and also a TMC4361A (or an Arm controller chip) to keep track of the encoder inputs / position?

  • Mario Nolten

    Hi Richard,
    yes, you are right, dcStep is an openLoop feature. Since you already have encoders assembled to your motors a combination of TMC4361 + TMC5160 is a very good solution. Here is a short guide how you can connect the TMC4361-BOB with a TMC5160-BOB:
    http://blog.trinamic.com/2018/04/09/realtime-motor-and-motion-control-with-a-raspberry-pi-without-a-realtime-os/
    The TMC4361 has an integrated sync pin which allows to syncronize several axis. Besides this the TMC4361 allows full closed control.
    Best regards,
    Mario

  • Ivo Ihlemann

    Hi,
    let me thank you first for this tutorial.
    I found a mistake: I’m pretty shure the last command should not be “sudo ~/TMCAPI_test/bin/TMCAPI_EXAMPLE”, but instead “sudo ~/TMC_EXAMPLE/bin/TMCAPI_EXAMPLE”

    Sincerely
    Ivo

  • Lucas

    Hi,
    how can the A (rms or max) for the motor be set on this board? Do I have to change some resistor on the pcb or can I do it via a TMCL command? Could not find any info on this.
    Sincerely,
    Lucas

  • Mario Nolten

    Hi Lucas,
    you can change the motor current by changing the IHOLD (current at standstill) and IRUN.
    // IHOLD=8, IRUN=15 (max. current), IHOLDDELAY=6
    tmc5160_writeInt(MOTOR0, TMC5160_IHOLD_IRUN, 0x00080F0A);
    Best regards,
    Mario

  • Bosh

    Am i right to assume that the same commands used to configure tmc2130 should work for this IC (want to use it without the motion controller). I know tmc2660 uses different registers but it seems tmc5160 uses the same ones as tmc2130. Is this correct? Don’t want to destroy them while trying :).

  • Benno

    Hello
    I have the following combination:
    Landungsbrücke-> TMC4361_eval-> TMC5160_eval
    Does the firmware of the Landungsbrücke have to be renewed?
    Best regards
    Benno

  • Mario Nolten

    Hi Benno,

    this combination is currently not supported by our TMCL-IDE because the TMC5160 needs to be selected as driver, not motion controller. We are currently working on a version that supports this.

    Best regards,
    Mario

  • Mario Nolten

    Hi,

    yes, the TMC5160 uses the same commands as the TMC2130 plus some additional ones.

    Best regards,
    Mario

  • Bahle Lucas

    Hi Mario,
    thank you very much. Sorry that I still have to ask:
    In the datasheet it says phase-current A is 2.8 (RMS), so for what is 8 standing for and for what is 15 standing for? Are these mapped numberspaces? Where can more information about those commands be found and what set number is giving what amp?
    Best regards

  • Lucas

    Thanks Mario,
    finally found it in the datasheet “TMC5160 DATASHEET (Rev. 1.06 / 2018-JUN-06)” on page 74. So do I understand it (?), when IRUN=31 is put, it takes 32/32 of the max A, e.g. 2.8A(RMS) for the tmc5160-BOB. If e.g. IRUN=15 it takes 16/32 of it, that would be 1.4A(RMS)? Does it work in that way?
    Best regards,
    Lucas

  • Mario Nolten

    Hi Lucas,
    this is correct.
    Best regards,
    Mario

  • Iain

    I’m developing with a 5130-bob, is there anything similar to this for the 5130? Or can I use this example and just change the includes to use 5130.h instead of 5160.h?

    I’m running it from a Raspberry Pi.

  • Mario Nolten

    Hi Iain,

    you can basically use the same code, include the 5130.h instead and rename tmc5160_writeInt(..) accordingly. For the TMC5130 you might want to use a slightly different configuration for GCONF.

    Best regards,
    Mario

  • Iain

    Thanks, I’ve got the 5130-bob driving a stepper quite nicely after fixing GCONF (basically 04 instead of 0C),however I notice that Your code is pretty basic and only supports a single motor (as mentioned above). I need to support multiple motors (at least 2, preferably 3 or 4),, which physically the pi is quite able to do.

    Are you likely to be changing the underlying packages (broadcom driver and wiringpi are both used in the code above).

    Can you give me any idea of the likely timescale for a multi motor version!

  • Mario Nolten

    Hi Ian,

    for supporting more than 1 motor you can simply change the code for the function “void tmc40bit_writeInt(u8 motor, uint8 address, int value)”. E.g. add a switch case and define an unique CS for each motor.

    As you mentioned this is a very basic example. An example for more than one motor would be great but is currently not planned.

    Best regards,
    Mario

  • Cristian Huijse

    Dear Mario

    We are trying to run this example with no success. The TMC5160_XACTUAL register reads the value that was written on the TMC5160_XTARGET register but the stepper motor does not move whatsoever. We have tried different power supplies, different motors and different raspberry boards. Could you give us a hint on how to debug this?

  • Mario Nolten

    Hi Christian,

    please make sure that DRV_ENN (9) on the TMC5160-BOB is at low level and that TMC5160_CHOPCONF is initialized properly.

    Best regards,
    Mario

  • Florian Becker

    Hallo Mario,

    ich habe ein Problem mit meinem TMC5160 EVAL. Ich habe dies über einen USB-Dongle direkt über SPI angeschlossen. Nun bin ich dabei die Register zu beschreiben und auszulesen. Die Kommunikatzion funktioniert auch soweit, ABER das Problem ist, wenn ich zu Beginn Register auslese, anschließend irgendwelche Register beschreibe und nun zB XACTUAL auslesen möchte, ein Pseudo-Wert angezeigt wird. Auch wenn das Register beim AUslesen nach dem fahren ein anderes ist, wird der gleiche Pseudo-Wert angezeigt. Woran kann das liegen? dies kommt mir sehr komisch vor

    Beste Grüße

  • Mario Nolten

    Hi Florian,

    am besten ist es hierfür unser Support System zu nutzen – der blaue Bubble, der sich auf jeder Seite befindet.

    Viele Grüße,
    Mario

  • Wolfgang

    Hello!
    Thanks for the delightful tutorial. I would like to integrate the TMC5160 in an existing project utilizing the STEP/DIR interface – as far as I understand it, the STEP/DIR interface is easily enabled by desoldering R2. Is here also an example for setting the necessary parameters (mainly current and microsteps, plus some Trinamic-specific settings) with a simple microcontroller via SPI in Arduino style?
    Yours Wolfi

  • Mario Nolten

    Hi Wolfi,
    we currently have no example that is using step/dir.
    Best regards,
    Mario

  • Iain

    I’ve written a very basic driver in python for the 5130 using the SPI interface, this is a lot easier to setup and run than the C code example and should be simple to adapt to other chips (like the 5160) that use the same interface technique.

    It is available at https://github.com/pootle/tripipy

  • Mario Nolten

    Hi,
    thank you for sharing your Python code. I think this can be very helpful.
    Great Work!
    Best regards,
    Mario

Leave a Reply

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