Skip to content

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
laurb9 committed Jun 30, 2017
2 parents 7aa0b40 + d1bf6b6 commit a304b8b
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@
*.exe
*.out
*.app

# Eclipse
.*project

# VScode
.vscode

2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
StepperDriver KEYWORD1

BasicStepperDriver KEYWORD1
DRV8880 KEYWORD1
DRV8834 KEYWORD1
DRV8824 KEYWORD1
DRV8825 KEYWORD1
Expand All @@ -14,6 +15,7 @@ move KEYWORD2
rotate KEYWORD2
setRPM KEYWORD2
getRPM KEYWORD2
setCurrent KEYWORD2
enable KEYWORD2
disable KEYWORD2
startMove KEYWORD2
Expand Down
4 changes: 2 additions & 2 deletions library.properties
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=*
120 changes: 120 additions & 0 deletions src/DRV8880.cpp
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);
}
63 changes: 63 additions & 0 deletions src/DRV8880.h
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

0 comments on commit a304b8b

Please sign in to comment.