-
Notifications
You must be signed in to change notification settings - Fork 0
/
A4988.hpp
118 lines (95 loc) · 2.61 KB
/
A4988.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*!
* \class A4988
* \file A4988.hpp
* \brief Class for A4988 servo motor control board
*
* \author Michael Pillon
*
*/
#include "mbed.h"
#ifndef A4988_hpp
#define A4988_hpp
/*!
Constants
*/
#define STEP_DELAY 1500 //!< DigitalOut delay in microseconds (Minimum 1000)
#define DEGREES_PER_STEP 1.8 //<! For NEMA 17 Stepper Motor
#define STEPS_PER_REVOLUTION 200 //!< # of FULL_STEP per full revolution
//!< Setting step direction based on the MSx outputs
#define FULL_STEP 1 //!< Low Low Low
#define HALF_STEP 2 //!< High Low Low
#define QUARTER_STEP 4 //!< Low High Low
#define EIGHTH_STEP 8 //!< High High Low
#define SIXTEENTH_STEP 16 //!< High High High
#define MS1_MASK 0x01
#define MS2_MASK 0x02 //<! Binary shift output >> 1
#define MS3_MASK 0x04 //<! Binary shift output >> 2
#define FORWARD 0
#define REVERSE 1
#define LEFT_TURN 2
#define RIGHT_TURN 3
#define HIGH 1
#define LOW 0
/*!
Data Types
*/
/*!
A4988
Servo motor control program
*/
class A4988 {
private:
DigitalOut step;
DigitalOut dir;
DigitalOut ms1;
DigitalOut ms2;
DigitalOut ms3;
int microStepMode;
char currentDirection;
public:
/*!
Constructor
\param step Pin for step signal
\param dir Pin for direction signal
\param ms1 Pin for MS1 microstepping mode register
\param ms2 Pin for MS2 microstepping mode register
\param ms3 Pin for MS3 microstepping mode register
*/
A4988(PinName step, PinName dir, PinName ms1, PinName ms2, PinName ms3);
/*!
Sets MSx outputs for requested step mode
FULL_STEP => Low Low Low
HALF_STEP => High Low Low
QUARTER_STEP => Low High Low
EIGHTH_STEP => High High Low
SIXTEENTH_STEP => High High High
\param newMode set mode for Microstepping
*/
void setStepMode();
void setStepMode(const uint8_t newMode);
void incStepMode();
void decStepMode();
/*!
Directly sets state of step pin
\param state HIGH/LOW
*/
void setStep(const uint8_t state);
/*!
Sets direction mode
When no argument is passed, direction is toggled
\param char mode enum for direction mode
*/
void setDirMode();
void setDirMode(const uint8_t mode) ;
/*!
Increments stepper motor desired number of steps
\param int stepCount number of steps to progress
*/
void increment(const uint16_t stepCount = 1) ;
/*!
Get Functions
*/
int getStepMode() ;
char getDirMode() ;
};
#endif