-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
194 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,10 @@ | |
*.exe | ||
*.out | ||
*.app | ||
|
||
# Eclipse | ||
.*project | ||
|
||
# VScode | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <Arduino.h> | ||
#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 |