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

11 Comments

  • Radek Reply

    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 Reply

      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 Reply

        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 Reply

          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 Reply

    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 Reply

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

    • Mario Nolten Reply

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

  • Richard Reply

    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?

Leave a Reply

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