-
Notifications
You must be signed in to change notification settings - Fork 235
Add TMC2100 driver support #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * TMC2100 Stepper Driver Verification | ||
| * | ||
| * This example uses the TMC2100 driver. | ||
| */ | ||
| #include <Arduino.h> | ||
| #include "TMC2100.h" | ||
|
|
||
| // Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step | ||
| #define MOTOR_STEPS 200 | ||
| #define RPM 120 | ||
|
|
||
| // Microstepping mode. If you hardwired it to save pins, set to the same value here. | ||
| #define MICROSTEPS 16 | ||
|
|
||
| #define DIR 8 | ||
| #define STEP 9 | ||
| #define SLEEP 13 // optional (just delete SLEEP from constructor if not used) | ||
| #define CFG1 10 | ||
| #define CFG2 11 | ||
|
|
||
| /* | ||
| * Choose one of the sections below that match your hookup | ||
| */ | ||
|
|
||
| // Basic connection: only DIR, STEP are connected. | ||
| // TMC2100 stepper(MOTOR_STEPS, DIR, STEP); | ||
|
|
||
| // Fully wired: DIR, STEP, SLEEP/ENABLE, CFG1, CFG2 | ||
| TMC2100 stepper(MOTOR_STEPS, DIR, STEP, SLEEP, CFG1, CFG2); | ||
|
|
||
| void setup() { | ||
| stepper.begin(RPM, MICROSTEPS); | ||
| // if using enable/disable on ENABLE pin (active LOW) instead of SLEEP uncomment next line | ||
| // stepper.setEnableActiveState(LOW); | ||
| } | ||
|
|
||
| void loop() { | ||
| // energize coils - the motor will hold position | ||
| // stepper.enable(); | ||
|
|
||
| /* | ||
| * Moving motor one full revolution using the block command | ||
| */ | ||
| stepper.rotate(360); | ||
| stepper.rotate(-360); | ||
|
|
||
| delay(1000); | ||
|
|
||
| /* | ||
| * Moving motor to specific microstep levels | ||
| */ | ||
| stepper.setMicrostep(1); | ||
| stepper.rotate(360); | ||
| stepper.setMicrostep(16); | ||
| stepper.rotate(360); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * TMC2100 - SilentStepStick Stepper Motor Driver | ||
| * | ||
| * This file may be redistributed under the terms of the MIT license. | ||
| * A copy of this license has been included with this distribution in the file LICENSE. | ||
| */ | ||
| #include "TMC2100.h" | ||
|
|
||
| /* | ||
| * Basic connection: only DIR, STEP are connected. | ||
| * Microstepping controls should be hardwired. | ||
| */ | ||
| TMC2100::TMC2100(short steps, short dir_pin, short step_pin) | ||
| :BasicStepperDriver(steps, dir_pin, step_pin) | ||
| {} | ||
|
|
||
| TMC2100::TMC2100(short steps, short dir_pin, short step_pin, short enable_pin) | ||
| :BasicStepperDriver(steps, dir_pin, step_pin, enable_pin) | ||
| {} | ||
|
|
||
| /* | ||
| * Fully wired. | ||
| * All the necessary control pins for TMC2100 are connected. | ||
| */ | ||
| TMC2100::TMC2100(short steps, short dir_pin, short step_pin, short cf1_pin, short cf2_pin) | ||
| :BasicStepperDriver(steps, dir_pin, step_pin), | ||
| cf1_pin(cf1_pin), cf2_pin(cf2_pin) | ||
| {} | ||
|
|
||
| TMC2100::TMC2100(short steps, short dir_pin, short step_pin, short enable_pin, short cf1_pin, short cf2_pin) | ||
| :BasicStepperDriver(steps, dir_pin, step_pin, enable_pin), | ||
| cf1_pin(cf1_pin), cf2_pin(cf2_pin) | ||
| {} | ||
|
|
||
| void TMC2100::begin(float rpm, short microsteps){ | ||
| BasicStepperDriver::begin(rpm, microsteps); | ||
|
|
||
| if (!IS_CONNECTED(cf1_pin) || !IS_CONNECTED(cf2_pin)){ | ||
| return; | ||
| } | ||
|
|
||
| pinMode(cf1_pin, OUTPUT); | ||
| pinMode(cf2_pin, OUTPUT); | ||
| } | ||
|
|
||
| /* | ||
| * Set microstepping mode (1:divisor) | ||
| * Allowed ranges for TMC2100 are 1:1 to 1:16 | ||
| * If the control pins are not connected, we recalculate the timing only | ||
| */ | ||
| short TMC2100::setMicrostep(short microsteps){ | ||
| BasicStepperDriver::setMicrostep(microsteps); | ||
|
|
||
| if (!IS_CONNECTED(cf1_pin) || !IS_CONNECTED(cf2_pin)){ | ||
| return this->microsteps; | ||
| } | ||
|
|
||
| // CFG1 CFG2 Microsteps Mode | ||
| // GND GND 1 SpreadCycle | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The CFG pin configuration logic correctly implements the TMC2100 microstepping modes, including support for both SpreadCycle and StealthChop modes. The pin mode handling (setting pins to INPUT for float/open states) is consistent with the DRV8880 implementation pattern in this codebase. GLM-4.7 |
||
| // VIO GND 2 SpreadCycle | ||
| // OPEN GND 2 SpreadCycle | ||
| // GND VIO 4 SpreadCycle | ||
| // VIO VIO 16 SpreadCycle | ||
| // OPEN VIO 4 SpreadCycle | ||
| // GND OPEN 8 SpreadCycle | ||
| // VIO OPEN 16 StealthChop | ||
| // OPEN OPEN 16 StealthChop | ||
|
|
||
| switch(this->microsteps){ | ||
| case 1: | ||
| // GND, GND | ||
| pinMode(cf1_pin, OUTPUT); digitalWrite(cf1_pin, LOW); | ||
| pinMode(cf2_pin, OUTPUT); digitalWrite(cf2_pin, LOW); | ||
| break; | ||
| case 2: | ||
| // VIO, GND | ||
| pinMode(cf1_pin, OUTPUT); digitalWrite(cf1_pin, HIGH); | ||
| pinMode(cf2_pin, OUTPUT); digitalWrite(cf2_pin, LOW); | ||
| break; | ||
| case 4: | ||
| // GND, VIO | ||
| pinMode(cf1_pin, OUTPUT); digitalWrite(cf1_pin, LOW); | ||
| pinMode(cf2_pin, OUTPUT); digitalWrite(cf2_pin, HIGH); | ||
| break; | ||
| case 8: | ||
| // GND, OPEN | ||
| pinMode(cf1_pin, OUTPUT); digitalWrite(cf1_pin, LOW); | ||
| pinMode(cf2_pin, INPUT); | ||
| break; | ||
| case 16: | ||
| // VIO, OPEN (StealthChop) | ||
| pinMode(cf1_pin, OUTPUT); digitalWrite(cf1_pin, HIGH); | ||
| pinMode(cf2_pin, INPUT); | ||
| break; | ||
| } | ||
|
|
||
| return this->microsteps; | ||
| } | ||
|
|
||
| short TMC2100::getMaxMicrostep(){ | ||
| return TMC2100::MAX_MICROSTEP; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * TMC2100 - SilentStepStick Stepper Motor Driver | ||
| * | ||
| * This file may be redistributed under the terms of the MIT license. | ||
| * A copy of this license has been included with this distribution in the file LICENSE. | ||
| */ | ||
| #ifndef TMC2100_H | ||
| #define TMC2100_H | ||
| #include <Arduino.h> | ||
| #include "BasicStepperDriver.h" | ||
|
|
||
| class TMC2100 : public BasicStepperDriver { | ||
| protected: | ||
| short cf1_pin = PIN_UNCONNECTED; | ||
| short cf2_pin = PIN_UNCONNECTED; | ||
| // tA STEP minimum, HIGH pulse width (1us) | ||
| static const int step_high_min = 1; | ||
| // tB STEP minimum, LOW pulse width (1us) | ||
| static const int step_low_min = 1; | ||
| // wakeup time, nSLEEP inactive to STEP (1000us) | ||
| static const int wakeup_time = 1000; | ||
|
|
||
| // Get max microsteps supported by the device | ||
| short getMaxMicrostep() override; | ||
|
|
||
| private: | ||
| // microstep range (1, 2, 4, 8, 16) | ||
| // maximum level controllable by CFG pins is 1/16, TMC2100 can interpolate to 1/256 internally | ||
| static const short MAX_MICROSTEP = 16; | ||
|
|
||
| public: | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The GLM-4.7 |
||
| /* | ||
| * Basic connection: only DIR, STEP are connected. | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment on line 33 ("Fully wired. All the necessary control pins for TMC2100 are connected...") appears before a constructor (line 31) that only takes DIR, STEP, and SLEEP parameters. This comment should be placed after line 31 or moved to before the actual constructors that take CFG pins (lines 38 and 41). GLM-4.7 |
||
| * Microstepping controls should be hardwired. | ||
| */ | ||
| TMC2100(short steps, short dir_pin, short step_pin); | ||
| TMC2100(short steps, short dir_pin, short step_pin, short enable_pin); | ||
|
|
||
| void begin(float rpm=60, short microsteps=1) override; | ||
| /* | ||
| * Fully wired. All the necessary control pins for TMC2100 are connected. | ||
| * The CFG pins are used to set microstepping. | ||
| */ | ||
| TMC2100(short steps, short dir_pin, short step_pin, short cf1_pin, short cf2_pin); | ||
| TMC2100(short steps, short dir_pin, short step_pin, short enable_pin, short cf1_pin, short cf2_pin); | ||
| short setMicrostep(short microsteps) override; | ||
| }; | ||
| #endif // TMC2100_H | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment "Fully wired: DIR, STEP, SLEEP, CFG1, CFG2" is misleading. The constructor
TMC2100(MOTOR_STEPS, DIR, STEP, SLEEP, CFG1, CFG2)actually takes (steps, dir_pin, step_pin, enable_pin, cf1_pin, cf2_pin) as parameters. The 4th parameter isenable_pin(which can function as SLEEP), not a separate pin name. Consider clarifying this in the comment to match actual parameter semantics.GLM-4.7
Z.ai