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

Dependents:   Steppermotor

Committer:
AjK
Date:
Mon May 02 10:17:33 2011 +0000
Revision:
3:71ab7209adb3
Parent:
1:1030a91cbf4c
Child:
4:7b7940df7865
1.0 See ChangeLog.h

Who changed what in which revision?

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