Trinamic TMC26X Stepper Driver for Arduino: TMC26XStepper.h Source File

Trinamic TMC26X Stepper Driver for Arduino

- Main Page
- Classes
- Files

- File List
- File Members

TMC26XStepper.h
Go to the documentation of this file.

    00001 /*
    00002  TMC26XStepper.cpp - - TMC26X Stepper library for Wiring/Arduino - Version 0.1
    00003
    00004  based on the stepper library by Tom Igoe, et. al.
    00005
    00006  Copyright (c) 2011, Interactive Matter, Marcus Nowotny
    00007
    00008  Permission is hereby granted, free of charge, to any person obtaining a copy
    00009  of this software and associated documentation files (the "Software"), to deal
    00010  in the Software without restriction, including without limitation the rights
    00011  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00012  copies of the Software, and to permit persons to whom the Software is
    00013  furnished to do so, subject to the following conditions:
    00014
    00015  The above copyright notice and this permission notice shall be included in
    00016  all copies or substantial portions of the Software.
    00017
    00018  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00019  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00020  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00021  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00022  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00023  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00024  THE SOFTWARE.
    00025
    00026  */
    00027
    00028
    00029 // ensure this library description is only included once
    00030 #ifndef TMC26XStepper_h
    00031 #define TMC26XStepper_h
    00032
    00034
    00039 #define TMC26X_OVERTEMPERATURE_PREWARING 1
    00040
    00041
    00047 #define TMC26X_OVERTEMPERATURE_SHUTDOWN 2
    00048
    00049 //which values can be read out
    00054 #define TMC26X_READOUT_POSITION 0
    00055
    00059 #define TMC26X_READOUT_STALLGUARD 1
    00060
    00064 #define TMC26X_READOUT_CURRENT 3
    00065
    00070 #define COOL_STEP_HALF_CS_LIMIT 0
    00071
    00075 #define COOL_STEP_QUARTDER_CS_LIMIT 1
    00076
    00101 class TMC26XStepper {
    00102   public:
    00124         TMC26XStepper(int number_of_steps, int cs_pin, int dir_pin, int step_pin, unsigned int current, unsigned int resistor=150);
    00125
    00133         void start();
    00134
    00145         void un_start();
    00146
    00147
    00152     void setSpeed(unsigned int whatSpeed);
    00153
    00158     unsigned int getSpeed(void);
    00159
    00168         void setMicrosteps(int number_of_steps);
    00169
    00178         int getMicrosteps(void);
    00179
    00195     char step(int number_of_steps);
    00196
    00215     char move(void);
    00216
    00224     char isMoving(void);
    00225
    00230     unsigned int getStepsLeft(void);
    00231
    00238     char stop(void);
    00239
    00264         void setConstantOffTimeChopper(char constant_off_time, char blank_time, char fast_decay_time_setting, char sine_wave_offset, unsigned char use_current_comparator);
    00265
    00286         void setSpreadCycleChopper(char constant_off_time, char blank_time, char hysteresis_start, char hysteresis_end, char hysteresis_decrement);
    00287
    00303         void setRandomOffTime(char value);
    00304
    00312         void setCurrent(unsigned int current);
    00313
    00320     unsigned int getCurrent(void);
    00321
    00337         void setStallGuardThreshold(char stall_guard_threshold, char stall_guard_filter_enabled);
    00338
    00343     char getStallGuardThreshold(void);
    00344
    00349     char getStallGuardFilter(void);
    00350
    00368     void setCoolStepConfiguration(unsigned int lower_SG_threshold, unsigned int SG_hysteresis, unsigned char current_decrement_step_size,
    00369                                   unsigned char current_increment_step_size, unsigned char lower_current_limit);
    00370
    00376     void setCoolStepEnabled(boolean enabled);
    00377
    00378
    00383     boolean isCoolStepEnabled();
    00384
    00389     unsigned int getCoolStepLowerSgThreshold();
    00390
    00395     unsigned int getCoolStepUpperSgThreshold();
    00396
    00401     unsigned char getCoolStepNumberOfSGReadings();
    00402
    00407     unsigned char getCoolStepCurrentIncrementSize();
    00408
    00414     unsigned char getCoolStepLowerCurrentLimit();
    00415
    00422         int getMotorPosition(void);
    00423
    00430         int getCurrentStallGuardReading(void);
    00431
    00437     unsigned char getCurrentCSReading(void);
    00438
    00439
    00444     boolean isCurrentScalingHalfed();
    00445
    00453     unsigned int getCurrentCurrent(void);
    00454
    00463         boolean isStallGuardOverThreshold(void);
    00464
    00471         char getOverTemperature(void);
    00472
    00480         boolean isShortToGroundA(void);
    00481
    00488         boolean isShortToGroundB(void);
    00495         boolean isOpenLoadA(void);
    00496
    00503         boolean isOpenLoadB(void);
    00504
    00511         boolean isStandStill(void);
    00512
    00524         boolean isStallGuardReached(void);
    00525
    00530     void setEnabled(boolean enabled);
    00531
    00537     boolean isEnabled();
    00538
    00548         void readStatus(char read_value);
    00549
    00554     int getResistor();
    00555
    00560         void debugLastStatus(void);
    00565     int version(void);
    00566
    00567   private:
    00568         unsigned int steps_left;                //the steps the motor has to do to complete the movement
    00569     int direction;        // Direction of rotation
    00570     unsigned long step_delay;    // delay between steps, in ms, based on speed
    00571     int number_of_steps;      // total number of steps this motor can take
    00572     unsigned int speed; // we need to store the current speed in order to change the speed after changing microstepping
    00573     unsigned int resistor; //current sense resitor value in milliohm
    00574
    00575     unsigned long last_step_time;      // time stamp in ms of when the last step was taken
    00576     unsigned long next_step_time;      // time stamp in ms of when the last step was taken
    00577
    00578         //driver control register copies to easily set & modify the registers
    00579         unsigned long driver_control_register_value;
    00580         unsigned long chopper_config_register;
    00581         unsigned long cool_step_register_value;
    00582         unsigned long stall_guard2_current_register_value;
    00583         unsigned long driver_configuration_register_value;
    00584         //the driver status result
    00585         unsigned long driver_status_result;
    00586
    00587         //helper routione to get the top 10 bit of the readout
    00588         inline int getReadoutValue();
    00589
    00590         //the pins for the stepper driver
    00591         unsigned char cs_pin;
    00592         unsigned char step_pin;
    00593         unsigned char dir_pin;
    00594
    00595         //status values
    00596         boolean started; //if the stepper has been started yet
    00597         int microsteps; //the current number of micro steps
    00598     char constant_off_time; //we need to remember this value in order to enable and disable the motor
    00599     unsigned char cool_step_lower_threshold; // we need to remember the threshold to enable and disable the CoolStep feature
    00600     boolean cool_step_enabled; //we need to remember this to configure the coolstep if it si enabled
    00601
    00602         //SPI sender
    00603         inline void send262(unsigned long datagram);
    00604 };
    00605
    00606 #endif
    00607