-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHundred_Steppers.h
114 lines (107 loc) · 3.7 KB
/
Hundred_Steppers.h
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
/*
* This is a library for controlling hundreds of steppers with a single
* arduino. 74HC595 chip is used to extend arduino's GPIO number, which
* accept serial data and transfer it into parallel output.
*
* 74HC595 pin-outs: | UNL2803(8 NPN darlington, 50V@500mA max):
* ____ | ____
* Q1 -|o |- VCC | Q0 -- I1 -|o |- O1
* Q2 -| |- Q0 | Q1 -- I2 -| |- O2
* Q3 -| |- DS | Q2 -- I3 -| |- O3
* Q4 -| |- OE | Q3 -- I4 -| |- O4
* Q5 -| |- STCP | Q4 -- I5 -| |- O5
* Q6 -| |- SHCP | Q5 -- I6 -| |- O6
* Q7 -| |- MR | Q6 -- I7 -| |- O7
* GND -|____|- Q7' | Q7 -- I8 -| |- O8
* | GND--GND -|____|- COMMON -- VCC
*
* Q0-Q7 -- parallel output
* DS -- dataPin, serial input
* OE -- enablePin, set to LOW to enable parallel output
* SHCP -- clockPin, SHift register Clock Pin
* STCP -- latchPin, STorage register Clock Pin
* MR -- clearPin, Master Reclear, set Q0-Q7 to LOW
* Q7' -- serial output to next cascaded DS
*
* You may need extra driver chip such as UNL2803 to offer enough
* current for stepper. Simply connect pins as showed above.
*
* Writtern by Hank @page https://github.com/hankso
*
* Stepper `24BYJ48` pin value table
* +---------+-------------------------------+
* |color pin| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
* +---------+-------------------------------+
* |red 5| H | H | H | H | H | H | H | H |
* |orange 4| L | L | | | | | | L |
* |yellow 3| | L | L | L | | | | |
* |pink 2| | | | L | L | L | | |
* |blue 1| | | | | | L | L | L |
* +---------+-------------------------------+
*/
#ifndef HUNDRED_STEPPERS_H
#define HUNDRED_STEPPERS_H
// Default it is uint8_t(only can be 0, 1, 2 or 3), you may want
// to set int16_t to storage current step since you can use HOME
// command to zero all motors.
#ifndef stepType
// #define stepType uint8_t
#define stepType int
#endif
class Hundred_Steppers
{
public:
// You can connect MR to VCC and OE to GND
// to simplify your hardeware and circuits.
Hundred_Steppers(uint16_t nSteppers, uint16_t nSteps,
uint8_t dataPin, uint8_t clockPin, uint8_t latchPin,
uint8_t clearPin = -1, uint8_t enablePin = -1,
uint8_t nStepperLines = 4, uint8_t driveMode = 4,
uint8_t speed = 10);
void
// control single stepper
setStepperStep(uint16_t, int),
// control a list of steppers
setStepperStep(int *, uint16_t),
setSpeedRevPerMin(uint16_t),
setSpeedRadPerSec(uint16_t),
// move all steppers towards zero
home(void);
uint16_t
getStepperNum(void);
bool
// steppers are default enabled if enablePin is offered
enableSteppers(void),
disableSteppers(void),
// this will clear all data in 74HC595 shift registers
clearShiftStorage(void),
setStepperNum(uint16_t);
private:
volatile uint8_t
*dataReg,
*clockReg,
*latchReg;
uint8_t
nStepperLines,
driveMode,
dataMask,
clockMask,
latchMask,
clearPin,
enablePin,
*cmdList;
uint16_t
nSteppers,
nSteps,
speedDelay;
stepType
*stepTable;
uint32_t
lastTime;
void
doStep(uint16_t length = 0),
fastShiftOut(uint8_t);
uint16_t
stepsToMove(int *, uint16_t);
};
#endif