ADI Trinamic Blog

We transform digital information into physical motion.

 
  • Newsletter
  • Blog Ethics
  • Legal/Impressum
  • Main Website
Menu
  • Newsletter
  • Blog Ethics
  • Legal/Impressum
  • Main Website
  • How to drive a stepper motor with your Arduino Mega using a TMC5130-EVAL

    Only a few wires including an SPI port are required to control TMC5130-EVAL with your Arduino. Here are the few steps required to get started.

    Preparation

    If your Arduino  is a 5V type you have to resolder one resistor on the TMC5130-EVAL from position R3 to R8. This sets the logic level of the TMC5130 to +5V. While by default the resistor is soldered to the “right-hand” position, you have to move it to the “left-hand” position for 5V operation.

    Extract from TMC5130-EVAL schematic

    Illustration 1 – Extract from TMC5130-EVAL schematic

    tmc5130-eval-logic-level-resistor

    Illustration 2 – Position of the logic level resistor on the TMC5130-EVAL board

    Wiring

    The wiring is very simple. You will need 8 jumper wires. To make the wiring more easy you can print out the TMC5130-EVAL_Pinning.pdf and cut out the template to mount it on the connector header of the TMC5130-EVAL (As seen on illustration 4). As a reference you can use the TMC5130-Eval_v15_01_Schematic.pdf. Here you’ll find the signals that are on each pin. The configuration is documented in the comment section of the Arduino code.

    Pinheader of TMC5130-EVAL

    Illustration 3 – Pinheader of TMC5130-EVAL

    Illustration 4 – TMC5130 wired up with Arduino Mega 2560

    Cable colors of illustration 4
    +5V –> red
    GND –> blue
    SDO –> yellow
    SDI –> orange
    SCK –> white
    CSN –> grey
    DRV_ENN –> black
    CLK16 –> green

    Using the internal CLK of the TMC5130

    This example uses an external CLK provided by the Arduino’s pin 11.

    You can use the internal CLK of the TMC5130 by tying the CLK16 signal to GND.

    Arduino Code

    The Arduino Code below does not need any additional libraries. The SPI library comes with the Arduino IDE. The program initializes the TMC5130 and executes a simple move to position cycle. It will rotate a 200 full step motor 10 revolutions to the one and 10 revolutions to the other direction depending on the wiring of the stepper motor. Please use either the TMC5130 datasheet or the TMCL IDE as a reference for the different registers.

    #include <SPI.h>
    #include "TMC5130_registers.h"
    
    /* The trinamic TMC5130 motor controller and driver operates through an 
     * SPI interface. Each datagram is sent to the device as an address byte
     * followed by 4 data bytes. This is 40 bits (8 bit address and 32 bit word).
     * Each register is specified by a one byte (MSB) address: 0 for read, 1 for 
     * write. The MSB is transmitted first on the rising edge of SCK.
     * 
     * Arduino Pins Eval Board Pins
     * 51 MOSI 32 SPI1_SDI
     * 50 MISO 33 SPI1_SDO
     * 52 SCK 31 SPI1_SCK
     * 25 CS 30 SPI1_CSN
     * 17 DIO 8 DIO0 (DRV_ENN)
     * 11 DIO 23 CLK16
     * GND 2 GND
     * +5V 5 +5V
     */
    
    
    int chipCS = 25;
    const byte CLOCKOUT = 11;
    // const byte CLOCKOUT = 9;   --> Uncomment for UNO, Duemilanove, etc...
    int enable = 17;
    
    void setup() {
     // put your setup code here, to run once:
     pinMode(chipCS,OUTPUT);
     pinMode(CLOCKOUT,OUTPUT);
     pinMode(enable, OUTPUT);
     digitalWrite(chipCS,HIGH);
     digitalWrite(enable,LOW);
    
     //set up Timer1
     TCCR1A = bit (COM1A0); //toggle OC1A on Compare Match
     TCCR1B = bit (WGM12) | bit (CS10); //CTC, no prescaling
     OCR1A = 0; //output every cycle
    
     SPI.setBitOrder(MSBFIRST);
     SPI.setClockDivider(SPI_CLOCK_DIV8);
     SPI.setDataMode(SPI_MODE3);
     SPI.begin();
    
     Serial.begin(9600);
    
     sendData(0x80,0x00000000); //GCONF
    
     sendData(0xEC,0x000101D5); //CHOPCONF: TOFF=5, HSTRT=5, HEND=3, TBL=2, CHM=0 (spreadcycle)
     sendData(0x90,0x00070603); //IHOLD_IRUN: IHOLD=3, IRUN=10 (max.current), IHOLDDELAY=6
     sendData(0x91,0x0000000A); //TPOWERDOWN=10
    
     sendData(0xF0,0x00000000); // PWMCONF
     //sendData(0xF0,0x000401C8); //PWM_CONF: AUTO=1, 2/1024 Fclk, Switch amp limit=200, grad=1
    
     sendData(0xA4,0x000003E8); //A1=1000
     sendData(0xA5,0x000186A0); //V1=100000
     sendData(0xA6,0x0000C350); //AMAX=50000
     sendData(0xA7,0x000186A0); //VMAX=100000
     sendData(0xAA,0x00000578); //D1=1400
     sendData(0xAB,0x0000000A); //VSTOP=10
    
     sendData(0xA0,0x00000000); //RAMPMODE=0
    
     sendData(0xA1,0x00000000); //XACTUAL=0
     sendData(0xAD,0x00000000); //XTARGET=0
    }
    
    void loop()
    {
     // put your main code here, to run repeatedly:
     sendData(0xAD,0x0007D000); //XTARGET=512000 | 10 revolutions with micro step = 256
     delay(20000);
     sendData(0x21,0x00000000);
     sendData(0xAD,0x00000000); //XTARGET=0
     delay(20000);
     sendData(0x21,0x00000000);
    }
    
    void sendData(unsigned long address, unsigned long datagram)
    {
     //TMC5130 takes 40 bit data: 8 address and 32 data
    
     delay(100);
     uint8_t stat;
     unsigned long i_datagram;
    
     digitalWrite(chipCS,LOW);
     delayMicroseconds(10);
    
     stat = SPI.transfer(address);
    
     i_datagram |= SPI.transfer((datagram >> 24) & 0xff);
     i_datagram <<= 8;
     i_datagram |= SPI.transfer((datagram >> 16) & 0xff);
     i_datagram <<= 8;
     i_datagram |= SPI.transfer((datagram >> 8) & 0xff);
     i_datagram <<= 8;
     i_datagram |= SPI.transfer((datagram) & 0xff);
     digitalWrite(chipCS,HIGH);
    
     Serial.print("Received: ");
     PrintHex40(stat, i_datagram);
     Serial.print("\n");
     Serial.print(" from register: ");
     Serial.println(address,HEX);
    }
    
    void PrintHex40(uint8_t stat, uint32_t data) // prints 40-bit data in hex with leading zeroes
    {
     char tmp[16];
     uint16_t LSB = data & 0xffff;
     uint16_t MSB = data >> 16;
     sprintf(tmp, "0x%.2X%.4X%.4X", stat, MSB, LSB);
     Serial.print(tmp);
    }
    

    Download

    The Arduino and TMC5130 zip file includes the pinning template, the TMC5130-EVAL schematic and the Arduino project.

    Related Pages

    • TMC5130A-TA
    • TMC5130-EVAL

    Share this:

    • Twitter
    • Facebook
    • LinkedIn
    • Pinterest
    • Print
    • Email

    Related

    April 5, 2017 / Lars Jaskulski / 59

    Categories: Code Snippet, Open Source Hardware, Products, Projects, Tutorial

    Trinamic spreadCycle™ & stealthChop™ technology for silent stepper motors explained How to drive a stepper motor with your Raspberry Pi 3/2 using a TMC5130-EVAL

    Comments are currently closed.

    59 thoughts on “How to drive a stepper motor with your Arduino Mega using a TMC5130-EVAL”

    • Lars Jaskulski says:
      April 6, 2017 at 9:55 am

      The next guide will explain howto use your Raspberry Pi 2 or 3 to communicate with the TMC5130-EVAL and turn the motor with a certain speed in velocity mode by the end of this week.

    • Convertini says:
      May 30, 2017 at 10:05 am

      Hi,
      if I attempt to compile this code I get this error message.
      Arduino: 1.8.2 (Windows 8.1), Board: “Arduino Due (Programming Port)”

      C:\Users\iRES-PC\Downloads\TMC5130-EVAL\TMC5130-EVAL.ino: In function ‘void setup()’:

      TMC5130-EVAL:34: error: ‘TCCR1A’ was not declared in this scope

      TCCR1A = bit (COM1A0); //toggle OC1A on Compare Match

      ^

      In file included from C:\Users\iRES-PC\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Arduino.h:44:0,

      from sketch\TMC5130-EVAL.ino.cpp:1:

      TMC5130-EVAL:34: error: ‘COM1A0’ was not declared in this scope

      TCCR1A = bit (COM1A0); //toggle OC1A on Compare Match

      ^

      C:\Users\iRES-PC\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/wiring_constants.h:93:25: note: in definition of macro ‘bit’

      #define bit(b) (1UL << (b))

      ^

      TMC5130-EVAL:35: error: 'TCCR1B' was not declared in this scope

      TCCR1B = bit (WGM12) | bit (CS10); //CTC, no prescaling

      ^

      In file included from C:\Users\iRES-PC\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Arduino.h:44:0,

      from sketch\TMC5130-EVAL.ino.cpp:1:

      TMC5130-EVAL:35: error: 'WGM12' was not declared in this scope

      TCCR1B = bit (WGM12) | bit (CS10); //CTC, no prescaling

      ^

      C:\Users\iRES-PC\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/wiring_constants.h:93:25: note: in definition of macro 'bit'

      #define bit(b) (1UL << (b))

      ^

      TMC5130-EVAL:35: error: 'CS10' was not declared in this scope

      TCCR1B = bit (WGM12) | bit (CS10); //CTC, no prescaling

      ^

      C:\Users\iRES-PC\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/wiring_constants.h:93:25: note: in definition of macro 'bit'

      #define bit(b) (1UL < Preferences.

    • Lars Jaskulski says:
      June 21, 2017 at 3:50 pm

      Hi Convertini,

      I just double checked with a fresh installation of Arduino IDE V1.8.3 and it compiles fine (with selected Arduino Uno Platform).
      From the error message I can see you try it with an Arduino Due which is an ARM platform. The code is based on the AVR. There might be some changes needed in the code.

      Did you try with a Arduino Leonardo or Mega?

      Best regards,
      Lars

    • j says:
      June 28, 2017 at 2:54 pm

      Hey,

      Thanks for the Blog post.
      Worked fine with the Arduino Nano.

      Do you know where i find other commands, to change the motor behavior?

      Best regard

      j

    • Lars Jaskulski says:
      June 28, 2017 at 3:03 pm

      Hi j,

      Great that it worked for you with the Nano. I am happy to hear that.

      The best reference is the TMC5130 datasheet which you can find here: https://www.trinamic.com/products/integrated-circuits/details/tmc5130a-ta/

      Is there something particular you are looking into?

      Best regards,
      Lars

    • qorckdtjs001 says:
      July 19, 2017 at 2:35 am

      HI j,
      I used this script to operate TMC5130-EVAL. actually i got the perfect result. Thanks

      but just before motor operation. i listen to high note noise from the motor.

      Is it happening to me alone?

      my motor is 1.2A , 24V and 17NEMA Stepper MOTOR

    • Lars Jaskulski says:
      July 19, 2017 at 11:18 am

      Hi,

      Great that the example worked for you. Have you tried stealthChop already? You can do so by changing the following code lines (line 46, 52 and 53).

      On line 46 please change the register value to 0x00000004. Comment line 52 and uncomment line 53.


      sendData(0x80,0x00000004); //GCONF

      //sendData(0xF0,0x00000000); // PWMCONF
      sendData(0xF0,0x000401C8); //PWM_CONF: AUTO=1, 2/1024 Fclk, Switch amp limit=200, grad=1

      This will enable the super silent stealthChop mode. Let me know if that worked for you and what you think.

      Best regards,
      Lars

    • qorckdtjs001 says:
      July 19, 2017 at 12:21 pm

      Oh, Thanks for your rep

      but i had already used that. anyway i will try again.

      and I want to know Silent MODE in the TMC2100 and TMC5130

      both differance? TMC2100 have very silent operation but TMC5130 is not

      plz tell me about that

      Best regards,
      Qor

    • Lars Jaskulski says:
      July 19, 2017 at 12:45 pm

      Hi Qor,

      To activate stealthChop with the TMC5130 the initial code in this post needs to be adapted a bit described in my previous answer. This will give you the same perfomance you experienced with the TMC2100.

      The perfomance with the TMC2100 and the TMC5130 is the same. With the TMC5130 you have some more flexibility to tune stealthChop due the fact you have registers with the SPI interface.

      Best regards,
      Lars

    • FW says:
      July 19, 2017 at 3:02 pm

      Hey Lars,

      great tutorial, it really helped me out a lot. As it happens, I’m currently working on a very similar project. I plan to power a motor with the TMC2660-EVAL board controlled by an Arduino. I wanted to drive the TMC2660 board via the step/direction interface, but this doesn’t seem to work.
      My backup plan now is to apply your SPI solution to my problem. I got one question though – Is it possible to use the register library for TMC5130 (TMC5130_registers.h)? Or is there a library for TMC2660?

      I would really appreciate your help on this topic.

      Kind regards,
      Finn

    • Lars Jaskulski says:
      July 19, 2017 at 3:11 pm

      Hi Finn,

      Thanks for the positive feedback. The wiring will be very close to the TMC5130 wiring described in this post. Anyhow there might be some transfer work involved.

      For the TMC2660 we have our TTAP (Trinamic Technology Access Package) available to download here: https://www.trinamic.com/support/software/access-package/

      It is an API and covers most of our chips. You’ll find the TMC2660 in the folder \TMC-EvalSystem\boards\TMC2660_eval.c

      This might help to get things started. The registers are build up differently and the datagram is only 20 bits. With the TMC5130 it is 40 bits.

      Please let me know if you need further assistance.

      Best regards,
      Lars

    • FW says:
      July 19, 2017 at 3:27 pm

      Hey Lars,

      thanks for the quick replay and pointing out the TTAP. I wasn’t really aware of that.

      Gonna work on that for now and see where I end up.

      Kind regards
      Finn

    • FW says:
      July 20, 2017 at 5:41 pm

      Hey Lars,

      me again… I’m still struggling with my TMC2660. I’m fairly certain I got it hooked up correctly, but I’m very unsettled how to configure the timer. I transferred some Basic Setup HEX-Codes from the TMC2660 documentation, but the board still seems dead. Also, it’s irritating to me that the return from SPI.transfer is 0xFF or 255 in decimal.

      If you happen to have spare time for this, I would much appreciate it, if you could have a quick look at my code (please keep in mind, I’m no expert):
      https://github.com/FinnWCode/TMC2660

      Kind Regards
      Finn

      PS: I got the jumpers on the board set to INT_S and INT_D., but EXT_S and EXT_D doesn’t change anything besides that I get 0 instead of 255 as return from transfer.

      PPS: My power supply delivers solid 24 V, the arduino obviously 5V.

    • qorckdtjs001 says:
      July 21, 2017 at 4:45 am

      Hi Lars,

      i give up to operate Stealth mode TMC5130 by SPI .

      So i going to use Step/Dir mode. In TMC5130 datesheet , for the Step/Dir mode. SP_MODE pin tied LOW

      but my TMC5130_EVAL have not that external pin. how to use Step/dir mode

      plz help me about that

      Best regards,
      Qor

    • FW says:
      July 21, 2017 at 9:37 am

      Me again…

      Is it possible, that I have to resolder R7 to position R8 in order to set the logic level to 5V?

    • Lars Jaskulski says:
      July 21, 2017 at 3:24 pm

      Hi Qor,

      I really want you to use stealthChop with SPI as well. What can I do to help you? What issues do you have? Using stealthChop with SPI is possible. It might be that you need to reduce the velocity. To do so please change the register value for VMAX to a lower value.

      If you like to use STEP/DIR there is a solder jumper located close to the TMC5130. Please download the layout data: https://www.trinamic.com/fileadmin/assets/Products/Eval_Drawings/TMC5130-Eval_v15_LayoutData.zip
      and open the TMC5130-Eval_v15_12_FullViewTop.pdf. You need to solder the R_SD solder jumper.

      Best regards,
      Lars

    • Lars Jaskulski says:
      July 21, 2017 at 3:32 pm

      Hi Finn,

      When R7 is assembled the V_IO get the supply from the 3V3 LDO. When disassembling R7 and assemble R8 +5V from the USB rail will be used.

      You might need to check the SPI function of Arduino. I am not sure if you can send 5 bytes as you have it in your github example code. Probably the TMC5130 example might help to do the SPI communication.

      I like to build up a TMC2660-EVAL setup to try it myself. I need some spare time and get back to you.

      Best regards,
      Lars

    • Lars Jaskulski says:
      July 27, 2017 at 11:29 am

      Hi Finn,
      Did you have success in the mean time? What I recognized is that the delay in your step generation seems to be fairly high. Might be the reason you do not experience any motor movement with a micro step resolution of 256. Looking forward to your reply.
      Best regards,
      Lars

    • FW says:
      July 27, 2017 at 11:40 am

      Hey Lars,

      thank you very much for your help.
      You are correct: The SPI.function can indeed only send one byte at a time. I got that fixed in the code linked in my github above.
      After correcting the delays in the step generation and adjusting the motor current, everything is up and running.
      Only concern I have at the moment is a very high pitched noise when the motor is powered on. But I am positive to fix that via the various settings the TMC2660 offers.

      Thanks again and kind regards
      Finn

    • Lars Jaskulski says:
      July 27, 2017 at 12:08 pm

      Hi Finn,

      Great!

      In regard of the high pitch noise: Please try to modify TOFF in the CHOPCONF register. TOFF = 1 is something you could try first. It might make sense to reduce TOFF to 1 when in standstill and get back to the default value before a movement starts. With TOFF = 0 you completely deactivate the driver stage. If you do not need any holding torque at this position this might be an option as well.

      Since this is off topic I will contact you directly so we can work on your application.

      Best regards,
      Lars

    • Chase Conrad says:
      August 15, 2017 at 7:26 pm

      Hello,
      I’m thinking about using a TMC5041 because I need to control two motors. Can this code be modified to work with a TMC5041, and how would I move two motors simultaneously? Any help is greatly appreciated.
      Thanks!
      Chase

    • Lars Jaskulski says:
      November 21, 2017 at 12:23 pm

      Hi Chase,

      Please check out the blog post from Mario: http://blog.trinamic.com/2017/08/02/how-to-drive-a-stepper-motor-via-uart-with-your-arduino-mega-using-a-tmc5072-eval/

      This is based on the TMC5072 dual axis driver band should be a very good starting point. The blog post from Mario usees the single wire UART interface, anyhow the structure of the program might help.

      The SPI communication with The TMC5130 and the TMC5041 is 40 bit so the SPI communication stays the same. The only thing to adapt is the register addressess when using this code example.

      To move motors simultaneously you would simple write the same values in the registers of each axis, for example the target position.

      Let me know if you have furrther questions.

      Best regards,
      Lars

    • Yakov says:
      January 30, 2018 at 1:56 pm

      Hi,
      if i want to write my own program with arduino and TMC5130 – where can i found a software manual? , or some more guidance and explanation of the syntax and addresses and the data that i need to send from arduino to the driver.
      TX

    • Peter says:
      March 8, 2018 at 3:12 pm

      Hi Lars I have spend now few week on Internet searching for solution of my problem without success my problem is I em currently upgrading my CNC so i bought some TMC262-BOB60.
      My problem is i want to run it only in step/ dir mode i have been trying write program for arduino nano to send driver configuration to run no success.
      all what i need is set driver to step/dir mode , step size , current limits , stall guard.
      Best regards
      Peter.

    • Lars Jaskulski says:
      March 8, 2018 at 3:18 pm

      Hi Peter,
      Have you checked the TOS-100 project with the sample code?
      https://github.com/trinamic/TMC26XStepper
      Best regards,
      Lars

    • Lars Jaskulski says:
      March 8, 2018 at 3:27 pm

      Hi Yakov,
      The datasheet of the TMC5130 has all the information that you need to know what to send to what address. Please check:
      https://www.trinamic.com/fileadmin/assets/Products/ICs_Documents/TMC5130_datasheet.pdf

      On page 29 the documentation of the registers start.

      Additionally you can check the TMC5130-EVAL manual:
      https://www.trinamic.com/fileadmin/assets/Products/Eval_Documents/TMC5130_Eval_manual.pdf

      The basic SPI communication described above is the start to write and read the registers and the rest is your software work 😉

      You can check our API as well (scroll to the bottom of the page):
      https://www.trinamic.com/support/software/access-package/

      Hope that helps,
      Best regards,
      Lars

    • Chuck says:
      March 25, 2018 at 5:43 pm

      Hello,

      We have been trying your TMC5130-EVAL-KIT and like the smooth operations and programming features using the Arduino. Can your TMCM-3212 three axis controller be run by an Arduino also? We have XYZ (three axis) projects we would like to adapt for the Arduino if this is possible. We also have a six axis requirement run from an Arduino, perhaps using two 3212’s?

      Thank you for your assistance.
      Chuck

    • Lars Jaskulski says:
      April 3, 2018 at 9:11 am

      Hello Chuck,

      The TMCM-3212 can in general be controlled by an Arduino as well. For this case you would use the TMCM-3212-TMCL version and the RS-485 interface. A connection thru USB might work as well. Furthermore you would send TMCL commands that are described in the TMCM-3212 Firmware manual which you can download here: https://www.trinamic.com/products/modules/details/tmcm-3212/#downloads-3

      Let me know if that is what you are looking for or if you have additional question.

      Best regards,
      Lars

    • Chuck says:
      April 3, 2018 at 5:46 pm

      Hello Lars,

      I just received from Digi-Key the TMCM-3212-TMCL board with the wire loom TMCM-G4-CABLE. I will be trying to use it for repetitive 3 axis motors production with an Arduino. I will store the TMCL 3 motors commands inside the 3212 as a single 3212 function.

      My question is: How do I call this stored function from an Arduino to run the 3 motors?

      If this works with an Arduino, I will buy another 3212 to try for the 6 axis production machines.

      Thank you for your assistance!
      Chuck

    • Chuck says:
      April 23, 2018 at 5:38 am

      Hello,

      I have been using the TMCM-3212-TMCL for 3 motors and getting it to work well using Direct Mode binary commands from an Arduino through a MAX RS385 board. I am learning the very powerful Stand Alone use using the TMCL creator to create my program I download into the 3212. Then with just a single 9 byte serial command from the Arduino I can run stored multi-motor routines from the 3212. This is just what I was looking for.

      Is there anything similar for the TMC5130 single motor controller? I noticed there is no 5130 software plugin for the TMCL–IDE 3.0, is this due to no 5130 memory capabilities like the 3212?

      Also it seems the only real difference between the 3212 and the 6 axis TMCM-6212 board is the 6212 has less motor current capability per motor. Are there any other real differences than that?

      Thank you.

      Chuck

    • Tony Mackenzie says:
      June 8, 2018 at 2:23 am

      Hi,

      What modification to this code will be needed to get this to run with a TMC5160?

      Best regards,
      Tony

    • ANNA says:
      June 20, 2018 at 5:55 am

      Hello Lars
      Great Work ,I need your help to work with TMC5160- TA. I am working with a driver with LPC1313 as its controller. I like to use STEP/DIR mode.please pass me any information you have about it.

    • Lars Jaskulski says:
      June 20, 2018 at 9:20 am

      Hi Anna,
      Thank you! Please use the support system on our webpage to get support for the TMC5160. Please understand that the comment section is intended to be used for the corresponding blog entry.
      You find a blue button on the bottom right on every page of our main webpage: trinamic.com
      Best regards,
      Lars

    • Lars Jaskulski says:
      June 20, 2018 at 9:24 am

      Hi Tony,
      This should be fairly easy to be done. Please compare the TMC5130 and TMC5160 datasheet. The SPI datagram is pretty much the same but the addresses differ. If you need further support please use our support system on the webpage http://trinamic.com. You find a blue button on the bottom right of each page. Please understand that the comment section is intended to be used for the respective article on this blog and that we can not support other products.
      Best regards,
      Lars

    • Alex M says:
      July 27, 2018 at 1:52 pm

      Hello,

      It seems I found bug/mistake in the TMC5130 datasheet. Have a look at the page 103 (23 DC Motor or Solenoid)

      There is:
      1) “Bits 8..0 control motor A and Bits 24..16 control motor B PWM”
      2) “Setting the corresponding PWM bits between -255 and +255 (signed, two’s complement numbers) will vary motor voltage from -100% to 100%.”

      If I understood it correctly only 8 bits used to regulate power from -100% to 100%. In that case it should be values -128 to +127 accordingly.
      Please correct me if I am wrong.

    • Daniel Frenkel says:
      August 4, 2018 at 11:14 pm

      Is there any reason or advantage to use the internal clock (CLK16) rather than the external clock provided by the SPI master?

    • BAEK says:
      August 6, 2018 at 3:11 am

      Hello Lars
      i`m using TMC5130 for my project. its a great!
      and i need your help to work with tmc5130-TA..
      in the introduce TMC5130 on youtube, there is a Button of actual position clear. right?
      I wanna working TMC5130 to reset Actual position
      Actually I am using the power shorting method. but it`s not smart
      so i wanna code about reset actual position or other thing

      Best regards,

    • Lars Jaskulski says:
      August 10, 2018 at 1:37 am

      Hello,
      You can simply write 0 to the actual position register.
      Best regards,
      Lars

    • BAEK says:
      August 16, 2018 at 7:08 am

      Hello Lars,
      Thank you for your reply.
      But the problem was not solved.
      Your method is to turn the motor back to its initial position.

      I want to know how to set the current position of the motor the initial value.

      Currently I am using the power off method to set initial value. Is there another way?

      Best regards,

    • Lars Jaskulski says:
      August 16, 2018 at 8:00 am

      Hello,
      If you want to reset the position you need to do the following:
      1) Set VMAX = 0 (If you don’t the motor will turn to the new target position if in position mode)
      2) Set the actual position to 0
      3) Set the target position to 0

      Hopefully that should give your intended results. If not let us know.

      Best regards,
      Lars

    • Lars Jaskulski says:
      August 16, 2018 at 8:26 am

      Hi Daniel,

      Please check page 114 of the TMC5130 datasheet Revision 1.15
      https://www.trinamic.com/fileadmin/assets/Products/ICs_Documents/TMC5130_datasheet_Rev1.15.pdf

      Here you’ll find information on using the internal or external CLK. If you need further help please use our support system on our webpage: http://www.trinamic.com/

      Best regards,
      Lars

    • Lars Jaskulski says:
      August 16, 2018 at 8:34 am

      Hi Alex,
      Thanks for the hint. We check your finding and correct it if needed and provide a new documentation with the next release of the datasheet.
      Much appreciated!
      Best regards,
      Lars

    • Christian says:
      August 28, 2018 at 9:28 am

      Hallo Lars,
      this is a wonderful work and a nice blog. I’m trying this with the TMC2130-EVAL, isn’t the code quite similar ? I was not sucessful with the EVAL-Kit, i.e. using the Landungsbrücke. The motor is blocking easily at high velocities (more than 200) or with microstepping (only up to halfstep 🙁 ), but this may be an issue of the motor. I want to setup StallGuard, which needs higher velocities, if I understood this right. My intention in using the arduino is that I’m driving a similar motor with the SilentStepStick 2130, which runs quite smoothly but so far without StallGuard.

    • Emil says:
      September 10, 2018 at 6:59 pm

      Hi Lars,

      Thanks for the example, it helped me getting started with TMC5130. However, I am having trouble enabling the dcStep feature of the controller. I am pretty sure I have set everything correctly, however, the motor misses steps and doesn’t slow down when I apply a load. Do you have any examples of how to configure the dcStep?

      Thanks!

    • Lars Jaskulski says:
      September 11, 2018 at 8:54 am

      Hi Christian,
      Please check out this application note: AN002-stallGuard2.pdf
      Best regards,
      Lars

    • Lars Jaskulski says:
      September 11, 2018 at 9:03 am

      Hi Emil,
      To make an example with dcStep is a good idea. Right now we can offer the application note AN003_-_dcStep_Basics_and_Wizard.pdf
      Please check if that helps you. If you have further questions or need additional support please do not hesitate to use our support system. You’ll find a blue button on every page of our main webpage: http://www.trinamic.com
      Best regards,
      Lars

    • jpv says:
      November 14, 2018 at 2:12 pm

      Hi Lars,
      First of all : congratulation for the whole Trinamic’s team for providing such good quality products.
      I m planning to make a robot with stepper. I m using teensy’s board for their powerfull chip, and software.
      I tried your code with a teensy 3.2 and the tmc5130 eval board, internal clock. It works perfectly (the line with stealth chop mode, didn’t work, but i ll try to take a look a the datasheet.), in exchange of a little change in the code concerning the SPI.
      For those who are interested here is the code :

      Modification for initializing SPI (put it before the setup function) :
      SPISettings settingsA(2000000, MSBFIRST, SPI_MODE3);

      In the setup, juste use SPI.begin()

      And modify the sendData function :

      void sendData(unsigned long address, unsigned long datagram) {
      //TMC5130 takes 40 bit data: 8 address and 32 data

      delay(100);
      unsigned long i_datagram;
      SPI.beginTransaction(settingsA);
      digitalWrite(chipCS,LOW);
      delayMicroseconds(10);

      SPI.transfer(address);

      i_datagram |= SPI.transfer((datagram >> 24) & 0xff);
      i_datagram <> 16) & 0xff);
      i_datagram <> 8) & 0xff);
      i_datagram <<= 8;
      i_datagram |= SPI.transfer((datagram) & 0xff);
      digitalWrite(chipCS,HIGH);
      SPI.endTransaction();
      Serial.print("Received: ");
      Serial.println(i_datagram,HEX);
      Serial.print(" from register: ");
      Serial.println(address,HEX);
      }

      Only 2Mhz speed tested, maybe fastest is possible.
      I now have a question : i bought the TMC5130 BOB. I can t find on the internet a way to control this with an arduino (or like) controller. So i will just try exactly the same thing i did with the eval board. But, are there any cautions to take? For exemple, i played with the tmc2130 Silentstepstick, with a tmc protector (from here https://www.watterott.com/), i had no problem. I removed the protector to try something : i toasted it! So, to summarize:
      Can i juste use the TMC5130 BOB as is (i put a large capacitor 330 uF, on the pcb, near power supply pins, as indicated), or must i use a protector circuit with it? If yes, witch one?
      Thanks in advance.
      Sincerly

    • Lars Jaskulski says:
      November 30, 2018 at 11:46 am

      Hi jpv,

      Thanks for your comment and the great feedback!

      In general you should be good using the BOB and connect it in the same way as the EVAL board. Additional protection is not necessary. You should of course avoid disconnecting motors with activated driver. If you need further assistance I would recommend our support system on our webpage. You’ll find a blue “button” on every page on http://www.trinamic.com

      Best regards,
      Lars

    • Zhesong Bing says:
      January 11, 2019 at 4:27 am

      I want to use the stallGuard function, which registers and bits should I concerned? Is there any code that I can use to learn?

    • Brett Kent says:
      February 4, 2019 at 3:33 pm

      Hi Lars,

      Do the parameters reset to default after power down? Do I need to reparameterize after each power up?
      Also will the tmc5160 behave similarily?

      Brett

    • Brett Kent says:
      February 5, 2019 at 8:47 pm

      Hi Lars,

      This works great on a mega but fails on a Uno,any idea why?
      I have checked pin numbers 1000 times to be sure.

      All registers return 0xFFFFFFFFFF

    • Lars Jaskulski says:
      February 6, 2019 at 9:26 am

      Hi Brett,
      My best guess would be the SPI library being used. The pins you use are important I assume. I suggest to check the SPI library in combination with the UNO.
      Hope that hint helps. Let me know if you solved it and if not, let me know as well 😉
      Best regards,
      Lars

    • Lars Jaskulski says:
      February 6, 2019 at 10:09 am

      Hi Brett,
      Yes, the registers need to be initialized after power up. That is for the TMC5130 and the TMC5160.
      Best regards,
      Lars

    • Lars Jaskulski says:
      February 6, 2019 at 10:15 am

      Hi,

      For StallGuard set a speed first and then read out the stallGuard value (DRV_STATUS register 0x6F). With that you will tune the SGT threshold value (COOLCONF register 0x6D).

      Here is an appnote for StallGuard and the technology:
      https://www.trinamic.com/fileadmin/assets/Support/Appnotes/AN002-stallGuard2.pdf

      Hope that this information helps.

      Best regards,
      Lars

    • Lars Jaskulski says:
      February 8, 2019 at 11:28 am

      Hi Brett,

      I just hurdled into something else related to this:

      You might need to use another pin to output the CLK for the TMC5130 with the UNO.

      Please replace
      const byte CLOCKOUT = 11; // Mega 2560
      with
      const byte CLOCKOUT = 9; // Uno, Duemilanove, etc.

      and rewire the pin for the CLK respectively.

      Hope that helps. Will add this to the code.

      Best regards,
      Lars

    • Maksym Ostapchuk says:
      February 20, 2019 at 6:53 pm

      Is this example comparable with driver tmc5160?

    • Lars Jaskulski says:
      February 21, 2019 at 5:42 pm

      Hi,
      The registers are different but the SPI datagram is the same. By adapting the code for the TMC5160 registers you can use a lot of code in this example.
      I will actually release a new blog post soon (might be tomorrow) that uses the TMC5160. Stay tuned!
      Best regards,
      Lars

    • Hajer says:
      December 12, 2019 at 11:52 am

      Hello Lars,

      I have two TMC5130-EVAL boards connected to an Arduino Mega. I am trying to make both motors move at the same time. I am not sure if this is possible, I tried setting the chip select pins properly, but only one motor would work and the other wouldn’t. My question is: is it possible to move both motors with just one Arduino and two 5130 evals or do I need a BOB? Any advice is appreciated.

      Kind regards,

      Hajer

    • Lars Jaskulski says:
      January 13, 2020 at 11:52 am

      Hi Hajer,

      That is possible. The ways how to do so are either to connect two CS signals to each board or to connect the TMC5130-EVALS in “daisy chain” mode. Daisy chain means that you are connecting one CS signal to the different CS of the TMC5130-EVAL boards and connect the first board’s MISO pin to the MOSI pin of the µController. The first boards MOSI goes to the second board’s MISO and the MOSI back to the µControllers MISO. With this approach you will need to send the datagram for both chips at once as soon as you put the CS to low respectively you send 80 bits instead of 40 bits.

      You could also use the single wire UART interface. There is an app note: link
      The app note is written for the TMC5072 but you can use it as a reference. The UART interface is described in the datasheet of the TMC5130A-TA as well won page 24.

      Hope that helps.
      Best regards,
      Lars

Recent Posts

  • Guest Blog: UBC Thunderbots
  • Guest Blog: TURAG
  • Guest Blog: School of Engineering Telecom Physics University of Strasbourg
  • Guest Blog: STAR Dresden
  • Pushing the Limits of Stepper Motor Control in 3D Printing

Social

  • View trinamic.mc’s profile on Facebook
  • View Trinamic_MC’s profile on Twitter
  • View trinamic’s profile on GitHub
  • View UC4SHA5_GAw1Wbm2T2NWpWbA’s profile on YouTube

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Newsletter

 

Info

Waterloohain 5
22769 Hamburg
+49 40 514 806 40

Tags

3D printer 3d printing arduino BLDC cDriver code code snippet coolStep drive Driver ease of use ethercat eval kit evaluation kit Field Oriented Control FOC GUI guide heliostat How-To IC linear stage motion controller motor driver open source hardware programming rtmi servo servo controller IC setup silentstepstick stealthChop stepper stepper motor stepper motor driver stepper motor driver ic stepper motors technology TMC4671 tmc5130 TMCL TMCL-IDE TRINAMIC TRINAMIC Motion Control tuning

Tag Cloud

    3D printer 3d printing arduino BLDC cDriver code code snippet coolStep drive Driver ease of use ethercat eval kit evaluation kit Field Oriented Control FOC GUI guide heliostat How-To IC linear stage motion controller motor driver open source hardware programming rtmi servo servo controller IC setup silentstepstick stealthChop stepper stepper motor stepper motor driver stepper motor driver ic stepper motors technology TMC4671 tmc5130 TMCL TMCL-IDE TRINAMIC TRINAMIC Motion Control tuning

Pages

  • Blog Ethics
  • Newsletter
  • Player Embed
  • Search Videos
  • User Videos
  • Video Category
  • Video Tag

Categories

  • Competition
  • Guest blog
  • Industry News
  • Jobs
  • Myths about Motors
  • Open Source Hardware
  • Products
  • Projects
    • DIY
    • University Projects
  • Research
  • Social
  • Software
  • technology
  • Trade Shows
  • Tutorial
    • Code Snippet
  • Uncategorized

Copyright © 2015 TRINAMIC BlogTheme created by PWT. Powered by WordPress.org

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.