Skip to content

Commit 69ac9d5

Browse files
committed
0.1.1 DRV8825
1 parent df5a7e4 commit 69ac9d5

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

libraries/DRV8825/DRV8825.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ class DRV8825
4747

4848
// CONFIGURATION
4949
// step pulse length is in microseconds
50-
// default 1.9 us
50+
// datasheet default = 1.9 us
5151
void setStepPulseLength(uint16_t us = 2);
5252
uint16_t getStepPulseLength();
5353

5454

55-
5655
protected:
5756
uint16_t _stepsPerRotation = 0;
5857
uint8_t _directionPin = 255;

libraries/DRV8825/README.md

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,18 @@ const uint8_t DRV8825_COUNTERCLOCK_WISE = 1; // HIGH
4444
### Constructor
4545

4646
- **DRV8825()** Constructor.
47-
48-
with steps per rotation as parameter.
49-
This parameter is optional and if set to zero, steps will not be counted.
5047
- **bool begin(uint8_t dirPin, uint8_t stepPin)** set the direction pin and step pin.
51-
Both pins are set to LOW. For direction this is DRV8825_CLOCK_WISE.
48+
Both pins are set to LOW. For direction this means DRV8825_CLOCK_WISE.
5249

5350

5451
### Direction
5552

5653
To define in which way the motor will turn.
5754

58-
- **void setDirection(uint8_t direction = DRV8825_CLOCK_WISE)**
55+
- **bool setDirection(uint8_t direction = DRV8825_CLOCK_WISE)**
5956
switch direction between DRV8825_CLOCK_WISE (0 = default) or
6057
DRV8825_COUNTERCLOCK_WISE (1).
58+
Returns false for other values.
6159
- **uint8_t getDirection()** returns DRV8825_CLOCK_WISE (0) or
6260
DRV8825_COUNTERCLOCK_WISE (1).
6361

@@ -75,24 +73,40 @@ This also updates the position and the steps counters.
7573
default to zero.
7674
Returns the last value of internal steps counter.
7775
- **uint32_t getSteps()** returns the steps made since start of the program or the last **resetSteps()**.
78-
- **bool setPosition(uint16_t pos = 0)** to calibrate the position of the motor. Default to zero.
79-
Works only if stepsPerRotation > 0
80-
Returns false if pos > stepsPerRotation.
81-
- **uint16_t getPosition()** returns the position % stepsPerRotation.
82-
Value = 0 .. stepsPerRotation - 1
76+
Its purpose is to have an indication of usage (wear and tear).
77+
- **bool setPosition(uint16_t pos = 0)** to calibrate the position of the motor. Default value is zero.
78+
Works only if stepsPerRotation > 0.
79+
Returns false if pos > stepsPerRotation.
80+
Note: it does not rotate the motor to a position.
81+
Note: there is no relation between position and steps.
82+
- **uint16_t getPosition()** returns the position which is kin the range 0 .. stepsPerRotation - 1.
8383
This value can be converted to an angle in degrees or radians.
8484

85+
86+
#### Some math
87+
88+
```cpp
89+
// angle in degrees.
90+
float angle = position * (360.0 / stepsPerRotation);
91+
92+
// angle in radians.
93+
float angle = position * (2.0 * PI / stepsPerRotation);
94+
95+
// wear and tear math.
96+
float rotations = getSteps() * (1.0 / stepsPerRotation);
97+
```
98+
8599
Note the behaviour of steps changed in 0.1.1.
86-
This is done as the library added position functions.
100+
This is done as the library added the position functions.
87101

88102

89103
### Configuration
90104

91105
- **void setStepPulseLength(uint16_t us = 2)** configures the pulse length of one step.
92-
It is defined in microseconds, default is 2 which is almost the 1.9 from the datasheet.
106+
This is defined in microseconds, default is 2 which is almost the 1.9 from the datasheet.
93107
Normally these need not to be changed.
94-
- **uint16_t getStepPulseLength()** returns the set value.
95-
Default = 2.
108+
- **uint16_t getStepPulseLength()** returns the set value in microseconds.
109+
Default the value = 2.
96110

97111

98112
## Operational
@@ -140,7 +154,7 @@ Some will only be worked on if requested and time permits.
140154
- reset pin RST 8.3.6
141155
- other?
142156
- if stepsPerRotation is set to zero, should pos be set to zero?
143-
- NB it will not be updated anymore.
157+
- NB it will not be updated any more.
144158
- do we need steps counter?
145159

146160
#### should

0 commit comments

Comments
 (0)