-
Notifications
You must be signed in to change notification settings - Fork 0
/
motor.h
executable file
·111 lines (97 loc) · 2.42 KB
/
motor.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
void enableDriver (void) {
digitalWrite (A4988enablePin, LOW);
}
void disableDriver (void) {
digitalWrite (A4988enablePin, HIGH);
}
// unsigned int convertPWM2TimerRegister (int s) {
// // Vmin y Vmax es distinta según el modo en el que estemos Video o TLapse
// if (STATE==RVM)
// //return map (s, 0,255,minVideoStepperFreqOCR1A, maxVideoStepperFreqOCR1A);
// return s;
// else
// return map (s, 0,255,minStepperFreqOCR1A, maxStepperFreqOCR1A);
// }
// void motorWillMove(void){
// // Empezamos a generar la onda cuadrada
// //enableTimer1Interrupt(convertPWM2TimerRegister(programParameters.speed)
// currentStepperSpeed = convertPWM2TimerRegister(programParameters.speed);
// //enableTimer1Interrupt();
// //enableTimer2Interrupt();
// enableTimer1InterruptForVideoMode();
// }
void processDirection(void) {
/* Switch de dirección */
if (digitalRead(dirSwitchPin)==HIGH)
digitalWrite (A4988dirPin,LOW);
else
digitalWrite (A4988dirPin, HIGH);
}
/*
void motorWillStop(void) {
// Deshabilitamos la interrupcion en Timer1
disableTimer1Interrupt();
//disableTimer2Interrupt();
}
*/
void moveMotorSteps (unsigned int s) {
digitalWrite (A4988stepPin, LOW);
for (unsigned int i=0; i<s; i++) {
digitalWrite (A4988stepPin, HIGH);
delay(5);
digitalWrite (A4988stepPin, LOW);
delay(5);
}
}
/*
DRV8825
*******
MS0 MS1 MS2
-------------------
Low Low Low Full step
High Low Low Half step
Low High Low 1/4 step
High High Low 1/8 step
Low Low High 1/16 step
High Low High 1/32 step
Low High High 1/32 step
High High High 1/32 step
A4988
*****
MS1 MS1 MS2
-------------------
Low Low Low Full step
High Low Low Half step
Low High Low Quarter step
High High Low Eighth step
High High High Sixteenth step
*/
void configureMicrosteping (char i) {
switch (i) {
case 1:
digitalWrite (A4988ms1Pin, LOW);
digitalWrite (A4988ms2Pin, LOW);
digitalWrite (A4988ms3Pin, HIGH);
break;
case 2:
digitalWrite (A4988ms1Pin, HIGH);
digitalWrite (A4988ms2Pin, LOW);
digitalWrite (A4988ms3Pin, LOW);
break;
case 4:
digitalWrite (A4988ms1Pin, LOW);
digitalWrite (A4988ms2Pin, HIGH);
digitalWrite (A4988ms3Pin, LOW);
break;
case 8:
digitalWrite (A4988ms1Pin, HIGH);
digitalWrite (A4988ms2Pin, HIGH);
digitalWrite (A4988ms3Pin, LOW);
break;
case 16:
digitalWrite (A4988ms1Pin, HIGH);
digitalWrite (A4988ms2Pin, HIGH);
digitalWrite (A4988ms3Pin, HIGH);
break;
}
}