Fully functional driver for the DRV88255 stepper motor driver. Includes microstepping, speed, disable and enable.
Dependents: Lidar_2D_Mapping Water Play Water_pump Lidar_2D_Mapping
Revision 0:a2a53dc49e0d, committed 2015-12-10
- Comitter:
- sventura3
- Date:
- Thu Dec 10 03:26:03 2015 +0000
- Child:
- 1:c8f423bfe891
- Commit message:
- fully functional
Changed in this revision
| DRV8825.cpp | Show annotated file Show diff for this revision Revisions of this file |
| DRV8825.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DRV8825.cpp Thu Dec 10 03:26:03 2015 +0000
@@ -0,0 +1,51 @@
+#include "DRV8825.h"
+#include "mbed.h"
+
+DigitalOut myled(LED1);
+
+DRV88255::DRV8825(PinName _en, PinName m0, PinName m1, PinName m2, PinName _stepPin, PinName dir):en(_en),
+ microstepping(m0, m1, m2),
+ stepPin(_stepPin),
+ direction(dir)
+{
+}
+
+void DRV8825::settings(float microstep, int dir, float speed)
+{
+ //Microsteppiing settings
+ if (microstep == 1) microstepping = 0;
+ else if (microstep == 1/2) microstepping = 1;
+ else if (microstep == 1/4) microstepping = 2;
+ else if (microstep == 1/8) microstepping = 3;
+ else if (microstep == 1/16) microstepping = 4;
+ else if (microstep == 1/32) microstepping = 5;
+
+ if (dir == 1) {
+ direction = 0;
+ } else if (dir == 0) {
+ direction = 1;
+ }
+
+ // Speeed or times per second
+ if(stepPin == 1){
+ stepPin = 0;
+ wait(1/speed);
+ }
+ else{
+ stepPin = 1;
+ wait(1/speed);
+ }
+ myled = stepPin;
+
+
+}
+
+void DRV8825::enable()
+{
+ en = 0;
+}
+
+void DRV8825::disable()
+{
+ en = 1;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DRV8825.h Thu Dec 10 03:26:03 2015 +0000
@@ -0,0 +1,19 @@
+#ifndef MBED_DRV8825_H
+#define MBED_DRV8825_H
+#endif
+
+#include "mbed.h"
+
+class DRV8825
+{
+public:
+ DRV8825(PinName _en, PinName m0, PinName m1, PinName m2, PinName _stepPin, PinName dir);
+ void settings(float microstep, int dir, float speed);
+ void enable();
+ void disable();
+private:
+ DigitalOut en;
+ BusOut microstepping;
+ DigitalOut stepPin;
+ DigitalOut direction;
+};
\ No newline at end of file