My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TMC26XExample.ino 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. TMC26XExample.ino - - TMC26X Stepper library Example for Wiring/Arduino
  3. Copyright (c) 2011, Interactive Matter, Marcus Nowotny
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. #include <SPI.h>
  21. #include <TMC26XStepper.h>
  22. //we have a stepper motor with 200 steps per rotation, CS pin 2, dir pin 6, step pin 7 and a current of 300mA
  23. TMC26XStepper tmc26XStepper = TMC26XStepper(200,2,6,7,700);
  24. int curr_step;
  25. int speed = 0;
  26. int speedDirection = 100;
  27. int maxSpeed = 1000;
  28. void setup() {
  29. Serial.begin(9600);
  30. Serial.println("==============================");
  31. Serial.println("TMC26X Stepper Driver Demo App");
  32. Serial.println("==============================");
  33. //set this according to you stepper
  34. Serial.println("Configuring stepper driver");
  35. //char constant_off_time, char blank_time, char hysteresis_start, char hysteresis_end, char hysteresis_decrement
  36. tmc26XStepper.setSpreadCycleChopper(2,24,8,6,0);
  37. tmc26XStepper.setRandomOffTime(0);
  38. tmc26XStepper.setMicrosteps(32);
  39. tmc26XStepper.setStallGuardThreshold(4,0);
  40. Serial.println("config finished, starting");
  41. tmc26XStepper.start();
  42. Serial.println("started");
  43. }
  44. void loop() {
  45. if (!tmc26XStepper.isMoving()) {
  46. speed+=speedDirection;
  47. if (speed>maxSpeed) {
  48. speed = maxSpeed;
  49. speedDirection = -speedDirection;
  50. } else if (speed<0) {
  51. speedDirection = -speedDirection;
  52. speed=speedDirection;
  53. }
  54. //setting the speed
  55. Serial.print("setting speed to ");
  56. Serial.println(speed);
  57. tmc26XStepper.setSpeed(speed);
  58. //we want some kind of constant running time - so the length is just a product of speed
  59. Serial.print("Going ");
  60. Serial.print(10*speed);
  61. Serial.println(" steps");
  62. tmc26XStepper.step(10*speed);
  63. } else {
  64. //we put out the status every 100 steps
  65. if (tmc26XStepper.getStepsLeft()%100==0) {
  66. Serial.print("Stall Guard: ");
  67. Serial.println(tmc26XStepper.getCurrentStallGuardReading());
  68. }
  69. }
  70. tmc26XStepper.move();
  71. }