Provides an API software interface to TIMER2 to control upto four stepper motors.

Dependents:   Steppermotor

Committer:
AjK
Date:
Fri May 20 09:13:31 2011 +0000
Revision:
4:7b7940df7865
Parent:
3:71ab7209adb3
1.1 See ChangeLog.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 4:7b7940df7865 1
AjK 4:7b7940df7865 2 #include "mbed.h"
AjK 4:7b7940df7865 3 #include "SimpleSteppers.h"
AjK 4:7b7940df7865 4
AjK 4:7b7940df7865 5 SimpleStepperOutput led1(LED1);
AjK 4:7b7940df7865 6
AjK 4:7b7940df7865 7 // SimpleStepperOutput is basically the same as
AjK 4:7b7940df7865 8 // Mbed's DigitalOut class. However, it's more
AjK 4:7b7940df7865 9 // portable to other platforms without having
AjK 4:7b7940df7865 10 // to also port the entire Mbed library.
AjK 4:7b7940df7865 11 SimpleStepperOutput sdir0(p17);
AjK 4:7b7940df7865 12 SimpleStepperOutput sdir1(p18);
AjK 4:7b7940df7865 13 SimpleStepperOutput sdir2(p19);
AjK 4:7b7940df7865 14 SimpleStepperOutput sdir3(p20);
AjK 4:7b7940df7865 15
AjK 4:7b7940df7865 16 // Create four steppers.
AjK 4:7b7940df7865 17 // Stepper0 has the pulse output on p8 and dir on p17
AjK 4:7b7940df7865 18 SimpleStepper stepper0(p8, &sdir0);
AjK 4:7b7940df7865 19 // Stepper1 has the pulse output on p7 and dir on p18
AjK 4:7b7940df7865 20 SimpleStepper stepper1(p7, &sdir1);
AjK 4:7b7940df7865 21 // Stepper2 has the pulse output on p7 and dir on p19
AjK 4:7b7940df7865 22 SimpleStepper stepper2(p6, &sdir2);
AjK 4:7b7940df7865 23 // Stepper3 has the pulse output on p7 and dir on p20
AjK 4:7b7940df7865 24 SimpleStepper stepper3(p5, &sdir3);
AjK 4:7b7940df7865 25
AjK 4:7b7940df7865 26 int main() {
AjK 4:7b7940df7865 27
AjK 4:7b7940df7865 28 // We do not need to maintain the stepper position
AjK 4:7b7940df7865 29 // for this simple example. This reduces the amount
AjK 4:7b7940df7865 30 // of work the ISR has to do.
AjK 4:7b7940df7865 31 stepper0.setMaintainPositionData(false);
AjK 4:7b7940df7865 32 stepper1.setMaintainPositionData(false);
AjK 4:7b7940df7865 33 stepper2.setMaintainPositionData(false);
AjK 4:7b7940df7865 34 stepper3.setMaintainPositionData(false);
AjK 4:7b7940df7865 35
AjK 4:7b7940df7865 36 // Set all steppers to top speed of 5000 pulses/second.
AjK 4:7b7940df7865 37 stepper0.setSpeed(5000);
AjK 4:7b7940df7865 38 stepper1.setSpeed(5000);
AjK 4:7b7940df7865 39 stepper2.setSpeed(5000);
AjK 4:7b7940df7865 40 stepper3.setSpeed(5000);
AjK 4:7b7940df7865 41
AjK 4:7b7940df7865 42 while(1) {
AjK 4:7b7940df7865 43 led1 = !led1;
AjK 4:7b7940df7865 44 wait(0.2);
AjK 4:7b7940df7865 45 }
AjK 4:7b7940df7865 46 }