From 515304b26460aef2da5220a817d5e693165e0afa Mon Sep 17 00:00:00 2001 From: Laurentiu Badea Date: Thu, 29 Jun 2017 22:20:02 -0700 Subject: [PATCH 1/3] updated .gitignore --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index b8bd026..dad1dcc 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,10 @@ *.exe *.out *.app + +# Eclipse +.*project + +# VScode +.vscode + From fbf654d793aa99eaea59ddefcbd5e14338c5d8d7 Mon Sep 17 00:00:00 2001 From: Laurentiu Badea Date: Thu, 29 Jun 2017 22:24:19 -0700 Subject: [PATCH 2/3] Add DRV8880 support (untested) #13 unique method setCurrent() for current/torque control --- src/DRV8880.cpp | 120 ++++++++++++++++++++++++++++++++++++++++++++++++ src/DRV8880.h | 63 +++++++++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 src/DRV8880.cpp create mode 100644 src/DRV8880.h diff --git a/src/DRV8880.cpp b/src/DRV8880.cpp new file mode 100644 index 0000000..b1f03b7 --- /dev/null +++ b/src/DRV8880.cpp @@ -0,0 +1,120 @@ +/* + * DRV8880 - 2A Stepper Motor Driver with AutoTune and Torque Control + * + * Copyright (C)2017 Laurentiu Badea + * + * 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 "DRV8880.h" + +/* + * Basic connection: only DIR, STEP are connected. + * Microstepping controls should be hardwired. + */ +DRV8880::DRV8880(short steps, short dir_pin, short step_pin) +:BasicStepperDriver(steps, dir_pin, step_pin) +{} + +DRV8880::DRV8880(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 DRV8880 are connected. + */ +DRV8880::DRV8880(short steps, short dir_pin, short step_pin, short m0, short m1) +:BasicStepperDriver(steps, dir_pin, step_pin), m0(m0), m1(m1) +{} + +DRV8880::DRV8880(short steps, short dir_pin, short step_pin, short enable_pin, short m0, short m1) +:BasicStepperDriver(steps, dir_pin, step_pin, enable_pin), m0(m0), m1(m1) +{} + +DRV8880::DRV8880(short steps, short dir_pin, short step_pin, short m0, short m1, short trq0, short trq1) +:BasicStepperDriver(steps, dir_pin, step_pin), m0(m0), m1(m1), trq0(trq0), trq1(trq1) +{} + +DRV8880::DRV8880(short steps, short dir_pin, short step_pin, short enable_pin, short m0, short m1, short trq0, short trq1) +:BasicStepperDriver(steps, dir_pin, step_pin, enable_pin), m0(m0), m1(m1), trq0(trq0), trq1(trq1) +{} + +void DRV8880::begin(short rpm, short microsteps){ + BasicStepperDriver::begin(rpm, microsteps); + setCurrent(100); +} + +short DRV8880::getMaxMicrostep(){ + return DRV8880::MAX_MICROSTEP; +} + +/* + * Set microstepping mode (1:divisor) + * Allowed ranges for DRV8880 are 1:1 to 1:16 + * If the control pins are not connected, we recalculate the timing only + */ +short DRV8880::setMicrostep(short microsteps){ + BasicStepperDriver::setMicrostep(microsteps); + + if (!IS_CONNECTED(m0) || !IS_CONNECTED(m1)){ + return this->microsteps; + } + + /* + * Step mode truth table + * M1 M0 step mode + * 0 0 1 + * 1 0 2 + * 1 1 4 + * 0 Z 8 + * 1 Z 16 + * + * 0 1 2 (non-circular, not implemented) + * Z = high impedance mode (M0 is tri-state) + */ + + pinMode(m1, OUTPUT); + pinMode(m0, OUTPUT); + switch(this->microsteps){ + case 1: + digitalWrite(m1, LOW); + digitalWrite(m0, LOW); + break; + case 2: + digitalWrite(m1, HIGH); + digitalWrite(m0, LOW); + break; + case 4: + digitalWrite(m1, HIGH); + digitalWrite(m0, HIGH); + break; + case 8: + digitalWrite(m1, LOW); + pinMode(m0, INPUT); // Z - high impedance + break; + case 16: + digitalWrite(m1, HIGH); + pinMode(m0, INPUT); // Z - high impedance + break; + } + return this->microsteps; +} + +void DRV8880::setCurrent(short percent){ + /* + * Torque DAC Settings table + * TRQ1 TRQ0 Current scalar + * 1 1 25% + * 1 0 50% + * 0 1 75% + * 0 0 100% + */ + if (!IS_CONNECTED(trq1) || !IS_CONNECTED(trq0)){ + return; + } + pinMode(trq1, OUTPUT); + pinMode(trq0, OUTPUT); + percent = (100-percent)/25; + digitalWrite(trq1, percent & 2); + digitalWrite(trq0, percent & 1); +} diff --git a/src/DRV8880.h b/src/DRV8880.h new file mode 100644 index 0000000..f4b444a --- /dev/null +++ b/src/DRV8880.h @@ -0,0 +1,63 @@ +/* + * DRV8880 - 2A Stepper Motor Driver with AutoTune and Torque Control + * + * Copyright (C)2017 Laurentiu Badea + * + * 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 DRV8880_H +#define DRV8880_H +#include +#include "BasicStepperDriver.h" + +class DRV8880 : public BasicStepperDriver { +protected: + short m0 = PIN_UNCONNECTED; + short m1 = PIN_UNCONNECTED; + short trq0 = PIN_UNCONNECTED; + short trq1 = PIN_UNCONNECTED; + // tWH(STEP) pulse duration, STEP high, min value + static const int step_high_min = 0; // 0.47us + // tWL(STEP) pulse duration, STEP low, min value + static const int step_low_min = 0; // 0.47us + // tWAKE wakeup time, nSLEEP inactive to STEP + static const int wakeup_time = 1500; + // also 200ns between ENBL/DIR/Mx changes and STEP HIGH + + // Get max microsteps supported by the device + short getMaxMicrostep() override; + +private: + // microstep range (1, 16, 32 etc) + static const short MAX_MICROSTEP = 16; + +public: + /* + * Basic connection: only DIR, STEP are connected. + * Microstepping controls should be hardwired. + */ + DRV8880(short steps, short dir_pin, short step_pin); + DRV8880(short steps, short dir_pin, short step_pin, short enable_pin); + /* + * DIR, STEP and microstep control M0, M1 + */ + DRV8880(short steps, short dir_pin, short step_pin, short m0, short m1); + DRV8880(short steps, short dir_pin, short step_pin, short enable_pin, short m0, short m1); + /* + * Fully Wired - DIR, STEP, microstep and current control + */ + DRV8880(short steps, short dir_pin, short step_pin, short m0, short m1, short trq0, short trq1); + DRV8880(short steps, short dir_pin, short step_pin, short enable_pin, short m0, short m1, short trq0, short trq1); + + void begin(short rpm=60, short microsteps=1); + + short setMicrostep(short microsteps) override; + + /* + * Torque DAC Control + * current percent value must be 25, 50, 75 or 100. + */ + void setCurrent(short percent=100); +}; +#endif // DRV8880_H From d1bf6b6ed8d4e4963c3034d6abbc2f2e86452941 Mon Sep 17 00:00:00 2001 From: Laurentiu Badea Date: Thu, 29 Jun 2017 22:28:42 -0700 Subject: [PATCH 3/3] 1.1.1 add DRV8880 support --- keywords.txt | 2 ++ library.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/keywords.txt b/keywords.txt index 55b78f9..e87755d 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,6 +1,7 @@ StepperDriver KEYWORD1 BasicStepperDriver KEYWORD1 +DRV8880 KEYWORD1 DRV8834 KEYWORD1 DRV8824 KEYWORD1 DRV8825 KEYWORD1 @@ -14,6 +15,7 @@ move KEYWORD2 rotate KEYWORD2 setRPM KEYWORD2 getRPM KEYWORD2 +setCurrent KEYWORD2 enable KEYWORD2 disable KEYWORD2 startMove KEYWORD2 diff --git a/library.properties b/library.properties index a7145b1..343c820 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=StepperDriver -version=1.1.0 +version=1.1.1 author=Laurentiu Badea maintainer=Laurentiu Badea sentence=A4988, DRV8825 and generic two-pin stepper motor driver library. -paragraph=Control steppers via a driver board providing STEP+DIR. Microstepping is supported. Acceleration is supported. Supported drivers are A4988, DRV8824, DRV8825, DRV8834. +paragraph=Control steppers via a driver board providing STEP+DIR. Microstepping is supported. Acceleration is supported. Supported drivers are A4988, DRV8824, DRV8825, DRV8834, DRV8880. category=Device Control url=https://github.com/laurb9/StepperDriver architectures=*