Trinamic TMC26X Stepper Driver for Arduino
Public Member Functions
TMC26XStepper Class Reference

Class representing a TMC26X stepper driver. More...

#include <TMC26XStepper.h>

List of all members.

Public Member Functions

 TMC26XStepper (int number_of_steps, int cs_pin, int dir_pin, int step_pin, unsigned int current, unsigned int resistor=150)
 creates a new represenatation of a stepper motor connected to a TMC26X stepper driver
void start ()
 configures and starts the TMC26X stepper driver. Before you called this function the stepper driver is in nonfunctional mode.
void un_start ()
 resets the stepper in unconfigured mode.
void setSpeed (unsigned int whatSpeed)
 Sets the rotation speed in revolutions per minute.
unsigned int getSpeed (void)
 reads out the currently selected speed in revolutions per minute.
void setMicrosteps (int number_of_steps)
 Set the number of microsteps in 2^i values (rounded) up to 256.
int getMicrosteps (void)
 returns the effective current number of microsteps selected.
char step (int number_of_steps)
 Initiate a movement for the given number of steps. Positive numbers move in one, negative numbers in the other direction.
char move (void)
 Central movement method, must be called as often as possible in the lopp function and is very fast.
char isMoving (void)
 checks if the motor still has to move to fulfill the last movement command.
unsigned int getStepsLeft (void)
 Get the number of steps left in the current movement.
char stop (void)
 Stops the motor regardless if it moves or not.
void setConstantOffTimeChopper (char constant_off_time, char blank_time, char fast_decay_time_setting, char sine_wave_offset, unsigned char use_current_comparator)
 Sets and configure the classical Constant Off Timer Chopper.
void setSpreadCycleChopper (char constant_off_time, char blank_time, char hysteresis_start, char hysteresis_end, char hysteresis_decrement)
 Sets and configures with spread cycle chopper.
void setRandomOffTime (char value)
 Use random off time for noise reduction (0 for off, -1 for on).
void setCurrent (unsigned int current)
 set the maximum motor current in mA (1000 is 1 Amp) Keep in mind this is the maximum peak Current. The RMS current will be 1/sqrt(2) smaller. The actual current can also be smaller by employing CoolStep.
unsigned int getCurrent (void)
 readout the motor maximum current in mA (1000 is an Amp) This is the maximum current. to get the current current - which may be affected by CoolStep us getCurrentCurrent()
void setStallGuardThreshold (char stall_guard_threshold, char stall_guard_filter_enabled)
 set the StallGuard threshold in order to get sensible StallGuard readings.
char getStallGuardThreshold (void)
 reads out the StallGuard threshold
char getStallGuardFilter (void)
 returns the current setting of the StallGuard filter
void setCoolStepConfiguration (unsigned int lower_SG_threshold, unsigned int SG_hysteresis, unsigned char current_decrement_step_size, unsigned char current_increment_step_size, unsigned char lower_current_limit)
 This method configures the CoolStep smart energy operation. You must have a proper StallGuard configuration for the motor situation (current, voltage, speed) in rder to use this feature.
void setCoolStepEnabled (boolean enabled)
 enables or disables the CoolStep smart energy operation feature. It must be configured before enabling it.
boolean isCoolStepEnabled ()
 check if the CoolStep feature is enabled
unsigned int getCoolStepLowerSgThreshold ()
 returns the lower StallGuard threshold for the CoolStep operation
unsigned int getCoolStepUpperSgThreshold ()
 returns the upper StallGuard threshold for the CoolStep operation
unsigned char getCoolStepNumberOfSGReadings ()
 returns the number of StallGuard readings befor CoolStep adjusts the motor current.
unsigned char getCoolStepCurrentIncrementSize ()
 returns the increment steps for the current for the CoolStep operation
unsigned char getCoolStepLowerCurrentLimit ()
 returns the absolut minium current for the CoolStep operation
int getMotorPosition (void)
 Get the current microstep position for phase A.
int getCurrentStallGuardReading (void)
 Reads the current StallGuard value.
unsigned char getCurrentCSReading (void)
 Reads the current current setting value as fraction of the maximum current Returns values between 0 and 31, representing 1/32 to 32/32 (=1)
boolean isCurrentScalingHalfed ()
 a convenience method to determine if the current scaling uses 0.31V or 0.165V as reference.
unsigned int getCurrentCurrent (void)
 Reads the current current setting value and recalculates the absolute current in mA (1A would be 1000). This method calculates the currently used current setting (either by setting or by CoolStep) and reconstructs the current in mA by usinge the VSENSE and resistor value. This method uses floating point math - so it may not be the fastest.
boolean isStallGuardOverThreshold (void)
 checks if there is a StallGuard warning in the last status
char getOverTemperature (void)
 Return over temperature status of the last status readout return 0 is everything is OK, TMC26X_OVERTEMPERATURE_PREWARING if status is reached, TMC26X_OVERTEMPERATURE_SHUTDOWN is the chip is shutdown, -1 if the status is unknown. Keep in mind that this method does not enforce a readout but uses the value of the last status readout. You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
boolean isShortToGroundA (void)
 Is motor channel A shorted to ground detected in the last status readout.
boolean isShortToGroundB (void)
 Is motor channel B shorted to ground detected in the last status readout.
boolean isOpenLoadA (void)
 iIs motor channel A connected according to the last statu readout.
boolean isOpenLoadB (void)
 iIs motor channel A connected according to the last statu readout.
boolean isStandStill (void)
 Is chopper inactive since 2^20 clock cycles - defaults to ~0,08s.
boolean isStallGuardReached (void)
 checks if there is a StallGuard warning in the last status
void setEnabled (boolean enabled)
 enables or disables the motor driver bridges. If disabled the motor can run freely. If enabled not.
boolean isEnabled ()
 checks if the output bridges are enabled. If the bridges are not enabled the motor can run freely
void readStatus (char read_value)
 Manually read out the status register This function sends a byte to the motor driver in order to get the current readout. The parameter read_value seletcs which value will get returned. If the read_vlaue changes in respect to the previous readout this method automatically send two bytes to the motor: one to set the redout and one to get the actual readout. So this method may take time to send and read one or two bits - depending on the previous readout.
int getResistor ()
 Returns the current sense resistor value in milliohm. The default value of ,15 Ohm will return 150.
void debugLastStatus (void)
 Prints out all the information that can be found in the last status read out - it does not force a status readout. The result is printed via Serial.
int version (void)
 library version

Detailed Description

Class representing a TMC26X stepper driver.

In order to use one fo those drivers in your Arduino code you have to create an object of that class:

 TMC26XStepper stepper = TMC26XStepper(200,1,2,3,500);

see TMC26XStepper(int number_of_steps, int cs_pin, int dir_pin, int step_pin, unsigned int rms_current)

Keep in mind that you need to start the driver with start() in order to get the TMC26X configured.

The most important function is the move(). It checks if the motor has to do a step or not. It is important that you call move() as often as possible in your Arduino loop() routine. I suggest to use a very fast loop routine and always call it at the beginning or the end.

In order to move you have to provide a movement speed with setSpeed(). The speed is a positive value setting the rotations per minute.

To really move the motor you have to call step() to tell the driver to move the motor the given number of steps in the given direction. Positive values move the motor in one direction, negative values in the other direction.

You can check with isMoving() if the mototr is still moving or stop it apruptely with stop().

Definition at line 101 of file TMC26XStepper.h.


Constructor & Destructor Documentation

TMC26XStepper::TMC26XStepper ( int  number_of_steps,
int  cs_pin,
int  dir_pin,
int  step_pin,
unsigned int  current,
unsigned int  resistor = 150 
)

creates a new represenatation of a stepper motor connected to a TMC26X stepper driver

This is the main constructor. If in doubt use this. You must provide all parameters as described below.

Parameters:
number_of_stepsthe number of steps the motor has per rotation.
cs_pinThe Arduino pin you have connected the Cient Select Pin (!CS) of the TMC26X for SPI
dir_pinthe number of the Arduino pin the Direction input of the TMC26X is connected
step_pinthe number of the Arduino pin the step pin of the TMC26X driver is connected.
rms_currentthe maximum current to privide to the motor in mA (!). A value of 200 would send up to 200mA to the motor
resistorthe current sense resistor in milli Ohm, defaults to ,15 Ohm ( or 150 milli Ohm) as in the TMC260 Arduino Shield

Keep in mind that you must also call TMC26XStepper.start() in order to configure the stepper driver for use.

By default the Constant Off Time chopper is used, see TCM262Stepper.setConstantOffTimeChopper() for details. This should work on most motors (YMMV). You may want to configure and use the Spread Cycle Chopper, see setSpreadCycleChopper().

By default a microstepping of 1/32th is used to provide a smooth motor run, while still giving a good progression per step. You can select a different stepping with setMicrosteps() to aa different value.

See also:
start(), setMicrosteps()

Definition at line 111 of file TMC26XStepper.cpp.


Member Function Documentation

Prints out all the information that can be found in the last status read out - it does not force a status readout. The result is printed via Serial.

Definition at line 902 of file TMC26XStepper.cpp.

returns the increment steps for the current for the CoolStep operation

See also:
setCoolStepConfiguration()

Definition at line 704 of file TMC26XStepper.cpp.

returns the absolut minium current for the CoolStep operation

See also:
setCoolStepConfiguration()
COOL_STEP_HALF_CS_LIMIT, COOL_STEP_QUARTER_CS_LIMIT

Definition at line 712 of file TMC26XStepper.cpp.

returns the lower StallGuard threshold for the CoolStep operation

See also:
setCoolStepConfiguration()

Definition at line 695 of file TMC26XStepper.cpp.

returns the number of StallGuard readings befor CoolStep adjusts the motor current.

See also:
setCoolStepConfiguration()

Definition at line 708 of file TMC26XStepper.cpp.

returns the upper StallGuard threshold for the CoolStep operation

See also:
setCoolStepConfiguration()

Definition at line 700 of file TMC26XStepper.cpp.

unsigned int TMC26XStepper::getCurrent ( void  )

readout the motor maximum current in mA (1000 is an Amp) This is the maximum current. to get the current current - which may be affected by CoolStep us getCurrentCurrent()

Returns:
the maximum motor current in milli amps
See also:
getCurrentCurrent()

Definition at line 336 of file TMC26XStepper.cpp.

unsigned char TMC26XStepper::getCurrentCSReading ( void  )

Reads the current current setting value as fraction of the maximum current Returns values between 0 and 31, representing 1/32 to 32/32 (=1)

See also:
setCoolStepConfiguration()

Definition at line 781 of file TMC26XStepper.cpp.

unsigned int TMC26XStepper::getCurrentCurrent ( void  )

Reads the current current setting value and recalculates the absolute current in mA (1A would be 1000). This method calculates the currently used current setting (either by setting or by CoolStep) and reconstructs the current in mA by usinge the VSENSE and resistor value. This method uses floating point math - so it may not be the fastest.

See also:
getCurrentCSReading(), getResistor(), isCurrentScalingHalfed(), getCurrent()

Definition at line 792 of file TMC26XStepper.cpp.

Reads the current StallGuard value.

Returns:
The current StallGuard value, lesser values indicate higher load, 0 means stall detected. Keep in mind that this routine reads and writes a value via SPI - so this may take a bit time.
See also:
setStallGuardThreshold() for tuning the readout to sensible ranges.

Definition at line 770 of file TMC26XStepper.cpp.

returns the effective current number of microsteps selected.

This function always returns the effective number of microsteps. This can be a bit different than the micro steps set in setMicrosteps() since it is rounded to 2^i.

See also:
setMicrosteps()

Definition at line 446 of file TMC26XStepper.cpp.

Get the current microstep position for phase A.

Returns:
The current microstep position for phase A 0…255

Keep in mind that this routine reads and writes a value via SPI - so this may take a bit time.

Definition at line 762 of file TMC26XStepper.cpp.

Return over temperature status of the last status readout return 0 is everything is OK, TMC26X_OVERTEMPERATURE_PREWARING if status is reached, TMC26X_OVERTEMPERATURE_SHUTDOWN is the chip is shutdown, -1 if the status is unknown. Keep in mind that this method does not enforce a readout but uses the value of the last status readout. You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.

Definition at line 816 of file TMC26XStepper.cpp.

Returns the current sense resistor value in milliohm. The default value of ,15 Ohm will return 150.

Definition at line 883 of file TMC26XStepper.cpp.

unsigned int TMC26XStepper::getSpeed ( void  )

reads out the currently selected speed in revolutions per minute.

See also:
setSpeed()

Definition at line 221 of file TMC26XStepper.cpp.

returns the current setting of the StallGuard filter

Returns:
0 if not set, -1 if set

Definition at line 381 of file TMC26XStepper.cpp.

reads out the StallGuard threshold

Returns:
a number between -64 and 63.

Definition at line 368 of file TMC26XStepper.cpp.

unsigned int TMC26XStepper::getStepsLeft ( void  )

Get the number of steps left in the current movement.

Returns:
The number of steps left in the movement. This number is always positive.

Definition at line 278 of file TMC26XStepper.cpp.

check if the CoolStep feature is enabled

See also:
setCoolStepEnabled()

Definition at line 691 of file TMC26XStepper.cpp.

a convenience method to determine if the current scaling uses 0.31V or 0.165V as reference.

Returns:
false if 0.13V is the reference voltage, true if 0.165V is used.

Definition at line 887 of file TMC26XStepper.cpp.

checks if the output bridges are enabled. If the bridges are not enabled the motor can run freely

Returns:
true if the bridges and by that the motor driver are enabled, false if not.
See also:
setEnabled()

Definition at line 729 of file TMC26XStepper.cpp.

char TMC26XStepper::isMoving ( void  )

checks if the motor still has to move to fulfill the last movement command.

Returns:
0 if the motor stops, -1 if the motor is moving.

This method can be used to determine if the motor is ready for new movements.

See also:
step(), move()

Definition at line 274 of file TMC26XStepper.cpp.

boolean TMC26XStepper::isOpenLoadA ( void  )

iIs motor channel A connected according to the last statu readout.

Returns:
true is yes, false if not. Keep in mind that this method does not enforce a readout but uses the value of the last status readout. You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.

Definition at line 846 of file TMC26XStepper.cpp.

boolean TMC26XStepper::isOpenLoadB ( void  )

iIs motor channel A connected according to the last statu readout.

Returns:
true is yes, false if not. Keep in mind that this method does not enforce a readout but uses the value of the last status readout. You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.

Definition at line 854 of file TMC26XStepper.cpp.

boolean TMC26XStepper::isShortToGroundA ( void  )

Is motor channel A shorted to ground detected in the last status readout.

Returns:
true is yes, false if not. Keep in mind that this method does not enforce a readout but uses the value of the last status readout. You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.

Definition at line 830 of file TMC26XStepper.cpp.

boolean TMC26XStepper::isShortToGroundB ( void  )

Is motor channel B shorted to ground detected in the last status readout.

Returns:
true is yes, false if not. Keep in mind that this method does not enforce a readout but uses the value of the last status readout. You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.

Definition at line 838 of file TMC26XStepper.cpp.

checks if there is a StallGuard warning in the last status

Returns:
0 if there was no warning, -1 if there was some warning. Keep in mind that this method does not enforce a readout but uses the value of the last status readout. You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
See also:
setStallGuardThreshold() for tuning the readout to sensible ranges.

Definition at line 803 of file TMC26XStepper.cpp.

checks if there is a StallGuard warning in the last status

Returns:
0 if there was no warning, -1 if there was some warning. Keep in mind that this method does not enforce a readout but uses the value of the last status readout. You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.
See also:
isStallGuardOverThreshold() TODO why?
setStallGuardThreshold() for tuning the readout to sensible ranges.

Definition at line 870 of file TMC26XStepper.cpp.

boolean TMC26XStepper::isStandStill ( void  )

Is chopper inactive since 2^20 clock cycles - defaults to ~0,08s.

Returns:
true is yes, false if not. Keep in mind that this method does not enforce a readout but uses the value of the last status readout. You may want to use getMotorPosition() or getCurrentStallGuardReading() to enforce an updated status readout.

Definition at line 862 of file TMC26XStepper.cpp.

char TMC26XStepper::move ( void  )

Central movement method, must be called as often as possible in the lopp function and is very fast.

This routine checks if the motor still has to move, if the waiting delay has passed to send a new step command to the motor and manages the number of steps yet to move to fulfill the current move command.

This function is implemented to be as fast as possible to call it as often as possible in your loop routine. The more regurlarly you call this function the better. In both senses of 'regularly': Calling it as often as possible is not a bad idea and if you even manage that the intervals you call this function are not too irregular helps too.

You can call this routine even if you know that the motor is not miving. It introduces just a very small penalty in your code. You must not call isMoving() to determine if you need to call this function, since taht is done internally already and only slows down you code.

How often you call this function directly influences your top miving speed for the motor. It may be a good idea to call this from an timer overflow interrupt to ensure proper calling.

See also:
step()

Definition at line 246 of file TMC26XStepper.cpp.

void TMC26XStepper::readStatus ( char  read_value)

Manually read out the status register This function sends a byte to the motor driver in order to get the current readout. The parameter read_value seletcs which value will get returned. If the read_vlaue changes in respect to the previous readout this method automatically send two bytes to the motor: one to set the redout and one to get the actual readout. So this method may take time to send and read one or two bits - depending on the previous readout.

Parameters:
read_valueselects which value to read out (0..3). You can use the defines TMC26X_READOUT_POSITION, TMC_262_READOUT_STALLGUARD, or TMC_262_READOUT_CURRENT
See also:
TMC26X_READOUT_POSITION, TMC_262_READOUT_STALLGUARD, TMC_262_READOUT_CURRENT

Definition at line 742 of file TMC26XStepper.cpp.

void TMC26XStepper::setConstantOffTimeChopper ( char  constant_off_time,
char  blank_time,
char  fast_decay_time_setting,
char  sine_wave_offset,
unsigned char  use_current_comparator 
)

Sets and configure the classical Constant Off Timer Chopper.

Parameters:
constant_off_timeThe off time setting controls the minimum chopper frequency. For most applications an off time within the range of 5μs to 20μs will fit. Setting this parameter to zero completely disables all driver transistors and the motor can free-wheel. 0: chopper off, 1:15: off time setting (1 will work with minimum blank time of 24 clocks)
blank_timeSelects the comparator blank time. This time needs to safely cover the switching event and the duration of the ringing on the sense resistor. For most low current drivers, a setting of 1 or 2 is good. For high current applications with large MOSFETs, a setting of 2 or 3 will be required. 0 (min setting) … (3) amx setting
fast_decay_time_settingFast decay time setting. Controls the portion of fast decay for each chopper cycle. 0: slow decay only, 1…15: duration of fast decay phase
sine_wave_offsetSine wave offset. Controls the sine wave offset. A positive offset corrects for zero crossing error. -3…-1: negative offset, 0: no offset,1…12: positive offset
use_curreent_comparatorSelects usage of the current comparator for termination of the fast decay cycle. If current comparator is enabled, it terminates the fast decay cycle in case the current reaches a higher negative value than the actual positive value. (0 disable, -1 enable).

The classic constant off time chopper uses a fixed portion of fast decay following each on phase. While the duration of the on time is determined by the chopper comparator, the fast decay time needs to be set by the user in a way, that the current decay is enough for the driver to be able to follow the falling slope of the sine wave, and on the other hand it should not be too long, in order to minimize motor current ripple and power dissipation. This best can be tuned using an oscilloscope or trying out motor smoothness at different velocities. A good starting value is a fast decay time setting similar to the slow decay time setting. After tuning of the fast decay time, the offset should be determined, in order to have a smooth zero transition. This is necessary, because the fast decay phase leads to the absolute value of the motor current being lower than the target current (see figure 17). If the zero offset is too low, the motor stands still for a short moment during current zero crossing, if it is set too high, it makes a larger microstep. Typically, a positive offset setting is required for optimum operation.

See also:
setSpreadCycleChoper() for other alternatives.
setRandomOffTime() for spreading the noise over a wider spectrum

Definition at line 473 of file TMC26XStepper.cpp.

void TMC26XStepper::setCoolStepConfiguration ( unsigned int  lower_SG_threshold,
unsigned int  SG_hysteresis,
unsigned char  current_decrement_step_size,
unsigned char  current_increment_step_size,
unsigned char  lower_current_limit 
)

This method configures the CoolStep smart energy operation. You must have a proper StallGuard configuration for the motor situation (current, voltage, speed) in rder to use this feature.

Parameters:
lower_SG_thresholdSets the lower threshold for stallGuard2TM reading. Below this value, the motor current becomes increased. Allowed values are 0...480
SG_hysteresisSets the distance between the lower and the upper threshold for stallGuard2TM reading. Above the upper threshold (which is lower_SG_threshold+SG_hysteresis+1) the motor current becomes decreased. Allowed values are 0...480
current_decrement_step_sizeSets the current decrement steps. If the StallGuard value is above the threshold the current gets decremented by this step size. 0...32
current_increment_step_sizeSets the current increment step. The current becomes incremented for each measured stallGuard2TM value below the lower threshold. 0...8
lower_current_limitSets the lower motor current limit for coolStepTM operation by scaling the CS value. Values can be COOL_STEP_HALF_CS_LIMIT, COOL_STEP_QUARTER_CS_LIMIT The CoolStep smart energy operation automatically adjust the current sent into the motor according to the current load, read out by the StallGuard in order to provide the optimum torque with the minimal current consumption. You configure the CoolStep current regulator by defining upper and lower bounds of StallGuard readouts. If the readout is above the limit the current gets increased, below the limit the current gets decreased. You can specify the upper an lower threshold of the StallGuard readout in order to adjust the current. You can also set the number of StallGuard readings neccessary above or below the limit to get a more stable current adjustement. The current adjustement itself is configured by the number of steps the current gests in- or decreased and the absolut minimum current (1/2 or 1/4th otf the configured current).
See also:
COOL_STEP_HALF_CS_LIMIT, COOL_STEP_QUARTER_CS_LIMIT

Definition at line 636 of file TMC26XStepper.cpp.

void TMC26XStepper::setCoolStepEnabled ( boolean  enabled)

enables or disables the CoolStep smart energy operation feature. It must be configured before enabling it.

Parameters:
enabledtrue if CoolStep should be enabled, false if not.
See also:
setCoolStepConfiguration()

Definition at line 676 of file TMC26XStepper.cpp.

void TMC26XStepper::setCurrent ( unsigned int  current)

set the maximum motor current in mA (1000 is 1 Amp) Keep in mind this is the maximum peak Current. The RMS current will be 1/sqrt(2) smaller. The actual current can also be smaller by employing CoolStep.

Parameters:
currentthe maximum motor current in mA
See also:
getCurrent(), getCurrentCurrent()

Definition at line 292 of file TMC26XStepper.cpp.

void TMC26XStepper::setEnabled ( boolean  enabled)

enables or disables the motor driver bridges. If disabled the motor can run freely. If enabled not.

Parameters:
enableda boolean value true if the motor should be enabled, false otherwise.

Definition at line 716 of file TMC26XStepper.cpp.

void TMC26XStepper::setMicrosteps ( int  number_of_steps)

Set the number of microsteps in 2^i values (rounded) up to 256.

This method set's the number of microsteps per step in 2^i interval. This means you can select 1, 2, 4, 16, 32, 64, 128 or 256 as valid microsteps. If you give any other value it will be rounded to the next smaller number (3 would give a microstepping of 2). You can always check the current microstepping with getMicrosteps().

Definition at line 394 of file TMC26XStepper.cpp.

void TMC26XStepper::setRandomOffTime ( char  value)

Use random off time for noise reduction (0 for off, -1 for on).

Parameters:
value0 for off, -1 for on

In a constant off time chopper scheme both coil choppers run freely, i.e. are not synchronized. The frequency of each chopper mainly depends on the coil current and the position dependant motor coil inductivity, thus it depends on the microstep position. With some motors a slightly audible beat can occur between the chopper frequencies, especially when they are near to each other. This typically occurs at a few microstep positions within each quarter wave. This effect normally is not audible when compared to mechanical noise generated by ball bearings, etc. Further factors which can cause a similar effect are a poor layout of sense resistor GND connection. In order to minimize the effect of a beat between both chopper frequencies, an internal random generator is provided. It modulates the slow decay time setting when switched on. The random off time feature further spreads the chopper spectrum, reducing electromagnetic emission on single frequencies.

Definition at line 624 of file TMC26XStepper.cpp.

void TMC26XStepper::setSpeed ( unsigned int  whatSpeed)

Sets the rotation speed in revolutions per minute.

Parameters:
whatSpeedthe desired speed in rotations per minute.

Definition at line 208 of file TMC26XStepper.cpp.

void TMC26XStepper::setSpreadCycleChopper ( char  constant_off_time,
char  blank_time,
char  hysteresis_start,
char  hysteresis_end,
char  hysteresis_decrement 
)

Sets and configures with spread cycle chopper.

Parameters:
constant_off_timeThe off time setting controls the minimum chopper frequency. For most applications an off time within the range of 5μs to 20μs will fit. Setting this parameter to zero completely disables all driver transistors and the motor can free-wheel. 0: chopper off, 1:15: off time setting (1 will work with minimum blank time of 24 clocks)
blank_timeSelects the comparator blank time. This time needs to safely cover the switching event and the duration of the ringing on the sense resistor. For most low current drivers, a setting of 1 or 2 is good. For high current applications with large MOSFETs, a setting of 2 or 3 will be required. 0 (min setting) … (3) amx setting
hysteresis_startHysteresis start setting. Please remark, that this value is an offset to the hysteresis end value. 1 … 8
hysteresis_endHysteresis end setting. Sets the hysteresis end value after a number of decrements. Decrement interval time is controlled by hysteresis_decrement. The sum hysteresis_start + hysteresis_end must be <16. At a current setting CS of max. 30 (amplitude reduced to 240), the sum is not limited.
hysteresis_decrementHysteresis decrement setting. This setting determines the slope of the hysteresis during on time and during fast decay time. 0 (fast decrement) … 3 (slow decrement).

The spreadCycle chopper scheme (pat.fil.) is a precise and simple to use chopper principle, which automatically determines the optimum fast decay portion for the motor. Anyhow, a number of settings can be made in order to optimally fit the driver to the motor. Each chopper cycle is comprised of an on-phase, a slow decay phase, a fast decay phase and a second slow decay phase. The slow decay phases limit the maximum chopper frequency and are important for low motor and driver power dissipation. The hysteresis start setting limits the chopper frequency by forcing the driver to introduce a minimum amount of current ripple into the motor coils. The motor inductivity determines the ability to follow a changing motor current. The duration of the on- and fast decay phase needs to cover at least the blank time, because the current comparator is disabled during this time.

See also:
setRandomOffTime() for spreading the noise over a wider spectrum

Definition at line 552 of file TMC26XStepper.cpp.

void TMC26XStepper::setStallGuardThreshold ( char  stall_guard_threshold,
char  stall_guard_filter_enabled 
)

set the StallGuard threshold in order to get sensible StallGuard readings.

Parameters:
stall_guard_threshold-64 … 63 the StallGuard threshold
stall_guard_filter_enabled0 if the filter is disabled, -1 if it is enabled

The StallGuard threshold is used to optimize the StallGuard reading to sensible values. It should be at 0 at the maximum allowable load on the otor (but not before). = is a good starting point (and the default) If you get Stall Gaurd readings of 0 without any load or with too little laod increase the value. If you get readings of 1023 even with load decrease the setting.

If you switch on the filter the StallGuard reading is only updated each 4th full step to reduce the noise in the reading.

See also:
getCurrentStallGuardReading() to read out the current value.

Definition at line 346 of file TMC26XStepper.cpp.

configures and starts the TMC26X stepper driver. Before you called this function the stepper driver is in nonfunctional mode.

This routine configures the TMC26X stepper driver for the given values via SPI. Most member functions are non functional if the driver has not been started. Therefore it is best to call this in your Arduino setup() function.

Definition at line 157 of file TMC26XStepper.cpp.

char TMC26XStepper::step ( int  number_of_steps)

Initiate a movement for the given number of steps. Positive numbers move in one, negative numbers in the other direction.

Parameters:
number_of_stepsThe number of steps to move the motor.
Returns:
0 if the motor was not moving and moves now. -1 if the motor is moving and the new steps could not be set.

If the previous movement is not finished yet the function will return -1 and not change the steps to move the motor. If the motor does not move it return 0

The direction of the movement is indicated by the sign of the steps parameter. It is not determinable if positive values are right or left This depends on the internal construction of the motor and how you connected it to the stepper driver.

You can always verify with isMoving() or even use stop() to stop the motor before giving it new step directions.

See also:
isMoving(), getStepsLeft(), stop()

Definition at line 229 of file TMC26XStepper.cpp.

char TMC26XStepper::stop ( void  )

Stops the motor regardless if it moves or not.

Returns:
-1 if the motor was moving and is really stoped or 0 if it was not moving at all.

This method directly and apruptely stops the motor and may be used as an emergency stop.

Definition at line 282 of file TMC26XStepper.cpp.

resets the stepper in unconfigured mode.

This routine enables you to call start again. It does not change anything in the internal stepper configuration or the desired configuration. It just marks the stepper as not yet startet. You do not have to reconfigure the stepper to start it again, but it is not reset to any factory settings this has to be configured back by yourself. (Hint: Normally you do not need this function)

Definition at line 199 of file TMC26XStepper.cpp.

int TMC26XStepper::version ( void  )

library version

Returns:
the version number as int.

Definition at line 897 of file TMC26XStepper.cpp.


The documentation for this class was generated from the following files: