• G-Codes
  • Configuration
  • Develop
  • About us
  • Privacy Policy

Repetier-Firmware - Configuration - Motors

Introduction

No printer, laser cutter or cnc mill would work without motors making all the moves. From firmware version 2 onwards we support up to 7 axis which can be controlled with linear, cubic or quintic velocity profiles. The first three axis X, Y, Z are for the spacial moves. E controls the current tools motor. A, B, C are not boudn to any special function and can be used for whatever you want. Of course more motors are more work to control and set signals for and will reduce the maximum stepper frequency. With the new design, we run always at the maximum frequency and see which stepper needs a step and run it. This concept requites no double or quad stepping and also has no delays that only suck up cpu power. It disables all signals at the start of the stepper function and enables those that need to go high.

Example: You set STEPPER_FREQUENCY to 100000 (due based board). That means every 10us the interrupt gets called. If you have a very fast stepper driver that works with 1ns low signals, you can have motors now run at 100KKhz maximum frequency. If motors need a longer high/low signal you reduce the max. speed to 50KHz. That means at max. speed the first interrupt turn signal on then 10us later it gets tuned off and NOT directly on. So the high and low signal are guaranteed to be on for 10us. Direction changes are done at the end of the stepper interrupt, so it also has one 10us before it gets used.

Basic settings that have influence on stepper drivers and motion control are these:

#define NUM_AXES 4                   // X,Y,Z and E for extruder A,B,C would be 5,6,7
#define STEPPER_FREQUENCY 250000     // Maximum stepper frequency.
#define PREPARE_FREQUENCY 2000       // Update frequency for new blocks. Must be higher then PREPARE_FREQUENCY.
#define BLOCK_FREQUENCY 1000         // Number of blocks with constant stepper rate per second.
#define VELOCITY_PROFILE 5           // 1 = linear, 3 = cubic, 5 = quintic velocity shape
#define Z_SPEED 10                   // Z positioning speed
#define XY_SPEED 100                 // XY positioning speed for normal operations
// Some common settings for trinamic driver settings
/**
 Chopper timing is an array with
 {toff, hend, hstrt}
 See TMC datasheets for more details. There are some predefined values to get you started:
 CHOPPER_TIMING_DEFAULT_12V = { 3, -1, 1 }
 CHOPPER_TIMING_DEFAULT_19V = { 4, 1, 1 }
 CHOPPER_TIMING_DEFAULT_24V = { 4, 2, 1 }
 CHOPPER_TIMING_DEFAULT_36V = { 5, 2, 4 }
 CHOPPER_TIMING_PRUSAMK3_24V = { 3, -2, 6 }

*/
#define TMC_CHOPPER_TIMING CHOPPER_TIMING_DEFAULT_12V
// true = interpolate to 256 microsteps for smoother motion
#define TMC_INTERPOLATE true
// Current used when motor stands still
#define TMC_HOLD_MULTIPLIER 0.5
// Reduce current on over temperature warnings by x milli ampere, 0 = disable
#define TMC_CURRENT_STEP_DOWN 50
// Define which data should be stored to eeprom
#define STORE_MOTOR_MICROSTEPPING 1
#define STORE_MOTOR_CURRENT 1
#define STORE_MOTOR_HYBRID_TRESHOLD 1
#define STORE_MOTOR_STEALTH 1
#define STORE_MOTOR_STALL_SENSITIVITY 1

NUM_AXES sets the number of axes you can control. 3 for CNC and 4 for 3d printer. More if you have additional needs.

Then there are 3 frequencies that need to be adjusted to work perfectly together and do leave enough CPU power for the remaining tasks. If these are set too high, strange things can happen. These demo values work fine for a due board with cartesian motion system and no display. The most time consuming is STEPPER_FREQUENCY. That is the maximum frequency a stepper can reach. The interrupt gets always called at that speed, even if no moves are active. To be able to use nonlinear velocity profiles, we split a move into many small constant speeds. That way cpu intensive computations get used for several succeeding steps leaving only a quite trivial problem for the stepper interrupt. The highe rthis value, the closer you are at the ideal motion, but the more cpu time you need. As a result increasing this value means you need to decrease the STEPPER_FREQUENCY to gain some more cpu power. A value of 1000 means every millisecond a new speed needs to be computed. PREPARE_FREQUENCY is directly connected to BLOCK_FREQUENCY. It is the frequency of the interrupt that updates the precomputed blocks. It must be higher then BLOCK_FREQUENCY and the double frequency seems a good compromise. With this you only get problems if you get several moves in a row that are shorter then 1/BLOCK_FREQUENCY seconds. Then you risk the buffers running empty.

VELOCITY_PROFILE defines, how smooth the printer should move. Until V2 it was always a linear move. This gives a yank to the printer that causes vibrations. You can reduce this, if you say the first derivative of speed should also be 0 (value 3, cubic aproximation). The smoothest acceleration curve is with second derivative also being 0 (value 5). For motion computation we always assume a linear acceleration. As a result a higher acceleration mid move is required. For cubic motions it is 150% and for quintic profiles 187.5% of the linear acceleration you set. This is normally no problem, because the acceleration is much smoother.

Motor Drivers

Simple stepper driver
Description

Controls a stepper driver by step, dir and enable signal directly connected to the processor.

Syntax
STEPPER_SIMPLE(name, stepPin, dirPin, enablePin, minEndstop, maxEndstop) 
Parameter
Parameter Function
name The variable name used to control the motor.
stepPin Pin variable for step line.
dirPin Pin variable for direction line. Use inverted signal if direction is wrong!
enablePin Pin variable for enable line. Use inverted signal if it does not enable for moves!
minEndstop Min end stop for this motor. In most cases it is no end stop as the axis end stop does the work.
maxEndstop Max end stop for this motor. In most cases it is no end stop as the axis end stop does the work.
Postprocess

Assign to axis.

TRINAMIC Stepper Driver
Description

Trinamic stepper drivers are often use for 3d printer, because they are very quiet and allow simple configuration over SPI/UART interface. Interesting features supported:

  • stealthChop - In this mode the moves are very silent. Torque may be reduced.
  • spreadCycle - A bit louder but more torque and allows detecting stalls.
  • Hybrid mode - Switch between stealthChop and spreadCycle depending on the speed.
  • Sensorless homing - the diag 1 pin becomes a end stop signal.
  • Current control - set motor current during operation.
  • Microstep configuration - switch online between full steps and 256 microsteps.
  • Prewarn for over temperatures - signals overheat condition in log.
  • Reduce current on over temperature - can reduce current when getting too hot.
  • Standstill cooldown - when not moving, the current is reduced to a hold level.
  • Daisy chaining - put multiple drivers in a line.

The currently supported drivers are:

  • TMC2208
  • TMC2209
  • TMC2130
  • TMC5160

To use sensorless homing, you need need to define a sensitivity between -64 and 63. 8 is a good start for testing. Select -128 to tell the firmware no sensorless homing/stallguard is wanted. The signal will be put on diag 1 output of the chip. Connect it to a sensor input defined by IO_INPUT_INVERTED_PULLUP.

There are many models and connection methods, therefore we list all supported variants and connection methods. Not all variants use the same parameter

Watch out with parameter mosiPin, misoPin, sckPin, csPin which are due to the fact that we use an existing library to control the driver the pin numbers and not INPUT/OUTPUT pin definitions!

Note: Chips requiring UART like TMC2208 only work with a hardware serial connection. Software UART would add too long interrupt prevention to ensure correct stepper handling.

These chips do not support sensorless homing: TMC2208.

Syntax
STEPPER_TMC2130_HW_SPI(name, stepPin, dirPin, enablePin, csPin, rsense, chainPos, microsteps, currentMillis, stealth, hybridSpeed, stallSensitivity, fclk, minEndstop, maxEndstop)
STEPPER_TMC2130_SW_SPI(name, stepPin, dirPin, enablePin, mosiPin, misoPin, sckPin, csPin, rsense, chainPos, microsteps, currentMillis, stealth, hybridSpeed, stallSensitivity, fclk, minEndstop, maxEndstop)
STEPPER_TMC5160_HW_SPI(name, stepPin, dirPin, enablePin, csPin, rsense, chainPos, microsteps, currentMillis, stealth, hybridSpeed, stallSensitivity, fclk, minEndstop, maxEndstop)
STEPPER_TMC5160_SW_SPI(name, stepPin, dirPin, enablePin, mosiPin, misoPin, sckPin, csPin, rsense, chainPos, microsteps, currentMillis, stealth, hybridSpeed, stallSensitivity, fclk, minEndstop, maxEndstop)
STEPPER_TMC2208_HW_UART(name, stepPin, dirPin, enablePin, serial, rsense, microsteps, currentMillis, stealth, hybridSpeed, fclk, minEndstop, maxEndstop)
STEPPER_TMC2209_HW_UART(name, stepPin, dirPin, enablePin, serial, rsense, microsteps, currentMillis, stealth, hybridSpeed, slaveAddr, stallSensitivity, fclk, minEndstop, maxEndstop)
Parameter
Parameter Function
name The variable name used to control the motor.
stepPin Pin variable for step line.
dirPin Pin variable for direction line. Use inverted signal if direction is wrong!
enablePin Pin variable for enable line. Use inverted signal if it does not enable for moves!
mosiPin MasterOutSlaveIn pin number. Connects to SDI or MISO on the stepper driver.
misoPin MasterInSlaveOut pin number. Connects to SDO or MOSI on the stepper driver.
sckPin Clock pin number.
csPin Pin number for chip select.
slaveAddr Address number for the chip.
rsense Resistance for current control.
Values for TMC2130:
  • 0.1: Panucatt BSD2660
  • 0.11: Watterott SilentStepStick boards
  • 0.15: IKS3D boards
  • 0.2: UltiMachine, Rambo Einsy and Archim2 boards
Values for TMC5160:
  • 0.075: Watterott SilentStepStick
chainPos Position in linked chain. Starts with 1. Only set differently if you chain them (same csPin, special extra wiring required).
microsteps Number of microsteps. Allowed values are 1, 2, 4, 8, 16, 32, 64, 128, 256.
currentMillis Maximum current per coil in milli ampere. Total current is 1.4142 times as high.
stealth Run in stealth mode or hybrid mode (true) or only in spreadCycle mode (false). For homing it will automatically move into spreadCycle when sensorless homing is enabled.
hybridSpeed Movement speed in mm/s (actually axis resolution * value steps per second) or 0 to disable it. When set slower moves < value will use silent mode and higher speeds use spreadCycle. If you change at a too high speed there might be a detectable phase change when switching from voltage to current regulated positioning, so select the value with care.
stallSensitivity Sensitivity when a stall gets detected. Range goes from -64 to 63. With a value of -128 you disable stall detection. The TMC2209 use stallguardv4 with range 0..255.
fclk Clockspeed of the driver. Normally 12500000 is a good value. Only used for hybridSpeed conversion.
minEndstop Min end stop for this motor. In most cases it is no end stop as the axis end stop does the work.
maxEndstop Max end stop for this motor. In most cases it is no end stop as the axis end stop does the work.
Postprocess

Assign to axis.

Mirror 2 motors
Description

Maps the motor signals to two stepper drivers. Used e.g. for Z axis with 2 motors. The printer gets configured with this driver instead and it ensures that both drivers get the same signals.

Syntax
STEPPER_MIRROR2(name, motor1, motor2, minEndstop, maxEndstop) 
Parameter
Parameter Function
name The variable name used to control the motor.
motor1 Variable of first motor driver.
motor2 Variable of the second motor driver.
minEndstop Min end stop for this motor. In most cases it is no end stop as the axis end stop does the work.
maxEndstop Max end stop for this motor. In most cases it is no end stop as the axis end stop does the work.
Postprocess

Assign to axis.

Mirror 3 motors
Description

Maps the motor signals to three stepper drivers. Used e.g. for Z axis with 3 motors. The printer gets configured with this driver instead and it ensures that all drivers get the same signals.

Syntax
STEPPER_MIRROR3(name, motor1, motor2, motor3, minEndstop, maxEndstop) 
Parameter
Parameter Function
name The variable name used to control the motor.
motor1 Variable of first motor driver.
motor2 Variable of the second motor driver.
motor3 Variable of the third motor driver.
minEndstop Min end stop for this motor. In most cases it is no end stop as the axis end stop does the work.
maxEndstop Max end stop for this motor. In most cases it is no end stop as the axis end stop does the work.
Postprocess

Assign to axis.

Mirror 4 motors
Description

Maps the motor signals to four stepper drivers. Used e.g. for Z axis with 4 motors. The printer gets configured with this driver instead and it ensures that all drivers get the same signals.

Syntax
STEPPER_MIRROR4(name, motor1, motor2, motor3, motor4, minEndstop, maxEndstop) 
Parameter
Parameter Function
name The variable name used to control the motor.
motor1 Variable of first motor driver.
motor2 Variable of the second motor driver.
motor3 Variable of the third motor driver.
motor4 Variable of the 4th motor driver.
minEndstop Min end stop for this motor. In most cases it is no end stop as the axis end stop does the work.
maxEndstop Max end stop for this motor. In most cases it is no end stop as the axis end stop does the work.
Postprocess

Assign to axis.

Observeable Stepper
Description

Maps the motor signals to given driver and keeps hold of a virtual position in steps. That way other modules can keep track of the motor position. Can be used to create a jam detector.

Syntax
STEPPER_OBSERVEABLE(name, driver) 
Parameter
Parameter Function
name The variable name used to control the motor.
driver Variable of motor driver.
Postprocess

Assign to axis.

Adjustable Resolution
Description

Maps a input resolution to an adjustable resolution. For example if you want that all extruders have the same resolution, lets say 500 steps/mm. Now it is likely that they do not really have that resolution. Resolutions will vary by a percent or two. But for ditto printing you have just one resolution for all. So here the adjustable resolution fits in. On the outside the firmware handles them as 500 steps per mm, but in reality the driver maps the 500 steps to any lower resolution you want. So one can have 350 steps per mm and the other 380 steps per mm but both will now extruder the same right amount.

Syntax
STEPPER_ADJUST_RESOLUTION(name, driver, from, to)
Parameter
Parameter Function
name The variable name used to control the motor.
driver Variable of motor driver for real motion.
from Resolution you want to fake. Must be an integer number.
to Real resolution of the driver. Must be an integer number.
Postprocess

Assign to axis.