-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstepper.ino
22 lines (20 loc) · 897 Bytes
/
stepper.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void IRAM_ATTR onLeftStepTimer() { // Interrupt function called by timer
digitalWrite(LEFT_STEP_PIN, HIGH);
delayMicroseconds(1);
digitalWrite(LEFT_STEP_PIN, LOW);
}
void IRAM_ATTR onRightStepTimer() { // Interrupt function called by timer
digitalWrite(RIGHT_STEP_PIN, HIGH);
delayMicroseconds(1);
digitalWrite(RIGHT_STEP_PIN, LOW);
}
void setupStepperTimers() {
leftStepTimer = timerBegin(2, 80, true); // 80Mhz / 80 = 1Mhz, 1microsecond
rightStepTimer = timerBegin(3, 80, true); // 80Mhz / 80 = 1Mhz, 1microsecond
timerAttachInterrupt(leftStepTimer, &onLeftStepTimer, true);
timerAttachInterrupt(rightStepTimer, &onRightStepTimer, true);
timerAlarmWrite(leftStepTimer, 1e17, true); // 1Mhz / # = rate // practically never
timerAlarmWrite(rightStepTimer, 1e17, true); // 1Mhz / # = rate
timerAlarmEnable(leftStepTimer);
timerAlarmEnable(rightStepTimer);
}