Wednesday, December 20, 2023

Library for TMC2209 driver - AVR

This library is used to control one or more TMC2209 modules via UART using an AVR microcontroller. Apart from reading and writing the TMC2209 registers, this library can also be used to drive a stepper motor by using the stepperCon library in the background. The stepperCon library provides non blocking functions by using an interrupt, to drive multiple stepper motors with custom acceleration and speed, to keep track of motor positions, 3-axis motor coordination, as well as other useful functions. UART library is also provided that can use up to 2 USART peripherals at the same time: one for interfacing with the driver IC and one for debugging (assuming the microcontroller has two USART peripherals). 

The serial communication has some extra features for checkup such as:

  • reads the interface transmission counter (IFCNT) register after every write to ensure the IC received the correct data.
  • compares CRCs.
  • checks if correct number of bytes has been received.
  • if an error occurs it retries 2 times then sets a communication error flag that the user can check after each function is executed and take the appropriate action if an error occurs. 

Library for TMC2209 driver - AVR
The principle of operation is read-modify-write so there is no need to keep all driver IC registers in memory. The library only uses an 8 bytes union structure called replyDatagram where received and data to send is stored temporary.

If you wish to learn on how to wire the TMC2209 driver, you can find a tutorial here.

Contents

Thursday, December 14, 2023

TMC2209 stepper driver module tutorial

My first stepper driver module was A4988 and recently I have decided to give TMC2209 a try hearing how silent and energy efficient it is. Driving the A4988 is simple - just set direction, pulse the step pin and the motor moves. You can do the same thing with TMC2209 but this thing can do much more. It has UART interface, registers, algorithms and an 83 pages datasheet. I might be slow but I had to read the datasheet 3 times to wrap my head around on what things can this thing do. In my opinion it is a very good stepper driver so I made a library for it and also this tutorial to better help in using the library. Although the IC presented in this tutorial is TMC2209, most information can still be applied to other TMC ICs.

Contents

 

TMC2209 description

The TMC2209 is an ultra-silent motor driver IC for two phase stepper motors, developed by trinamic. TMC2209 pinning is compatible to other drivers as well as to the TMC2208. 

TMC2209 stepper driver module tutorial
Multiple versions of modules can be found that are using this IC, however the stand-alone chip can be used for a DIY module that could provide some cost savings.

Features:

  • 2-phase stepper motors up to 2.8A coil current (peak), 2A RMS
  • STEP/DIR Interface with 8, 16, 32 or 64 microstep pin setting
  • Smooth Running 256 microsteps by MicroPlyer™ interpolation
  • StealthChop2™ silent motor operation
  • SpreadCycle™ highly dynamic motor control chopper
  • StallGuard4™ load and stall detection for StealthChop
  • CoolStep™ current control for energy savings up to 75%
  • Low RDSon, Low Heat-Up LS 170mΩ & HS 170mΩ (typ. at 25°C)
  • Voltage Range 4.75… 29V DC
  • Internal Sense Resistor option (no sense resistors required)
  • Passive Braking, Freewheeling, and automatic power down
  • Single Wire UART & OTP for advanced configuration options
  • Integrated Pulse Generator for standalone motion