Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:6e0a307d0f9b, committed 2013-05-13
- Comitter:
- mdu7078
- Date:
- Mon May 13 16:19:54 2013 +0000
- Parent:
- 0:acf5b8fc382b
- Commit message:
- First commit of mMotor library
Changed in this revision
| mMotor.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mMotor.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/mMotor.cpp Wed Apr 24 17:39:30 2013 +0000
+++ b/mMotor.cpp Mon May 13 16:19:54 2013 +0000
@@ -58,6 +58,10 @@
wait_us(motorSpeed); // wait time defines the speed
}
+ _M0 = 0;
+ _M1 = 0;
+ _M2 = 0;
+ _M3 = 0;
}
void mMotor::clockwise() { // rotate the motor 1 step clockwise
@@ -95,7 +99,87 @@
wait_us(motorSpeed); // wait time defines the speed
}
+ _M0 = 0;
+ _M1 = 0;
+ _M2 = 0;
+ _M3 = 1;
}
+
+void mMotor::ht_clockwise() { // rotate the motor 1 step clockwise
+ for (int i = 0; i < 4; i++) {
+ switch (i) { // activate the ports A0, A2, A3, A3 in a binary sequence for steps
+ case 0: {
+ _M0=1;
+ _M1=0;
+ _M2=0;
+ _M3=0;
+ }
+ break;
+ case 1: {
+ _M0=0;
+ _M1=1;
+ _M2=0;
+ _M3=0;
+ }
+ break;
+ case 2: {
+ _M0=0;
+ _M1=0;
+ _M2=1;
+ _M3=0;
+ }
+ break;
+ case 3: {
+ _M0=0;
+ _M1=0;
+ _M2=0;
+ _M3=1;
+ }
+ break;
+ }
+
+ wait_us(motorSpeed); // wait time defines the speed
+ }
+}
+
+void mMotor::ht_counterclockwise() { // rotate the motor 1 step anticlockwise
+ for (int i = 0; i < 4; i++) {
+ switch (i) { // activate the ports A0, A2, A3, A3 in a binary sequence for steps
+ case 0: {
+ _M0=0;
+ _M1=0;
+ _M2=0;
+ _M3=1;
+ }
+ break;
+ case 1: {
+ _M0=0;
+ _M1=0;
+ _M2=1;
+ _M3=0;
+ }
+ break;
+ case 2: {
+ _M0=0;
+ _M1=1;
+ _M2=0;
+ _M3=0;
+ }
+ break;
+ case 3: {
+ _M0=1;
+ _M1=0;
+ _M2=0;
+ _M3=0;
+ }
+ break;
+ }
+
+ wait_us(motorSpeed); // wait time defines the speed
+ }
+}
+
+
void mMotor::step(int num_steps, int direction, int speed) {// steper function: number of steps, direction (0- right, 1- left), speed (default 1200)
int count=0; // initalize step count
motorSpeed=speed; //set motor speed
@@ -110,4 +194,20 @@
count++;
} while (count<num_steps);// turn number of steps applied
+}
+
+void mMotor::ht_step(int num_steps, int direction, int speed) {// steper function: number of steps, direction (0- right, 1- left), speed (default 1200)
+ int count=0; // initalize step count
+ motorSpeed=speed; //set motor speed
+ if (direction==0) // turn clockwise
+ do {
+ ht_clockwise();
+ count++;
+ } while (count<num_steps); // turn number of steps applied
+ else if (direction==1)// turn anticlockwise
+ do {
+ ht_counterclockwise();
+ count++;
+ } while (count<num_steps);// turn number of steps applied
+
}
\ No newline at end of file
--- a/mMotor.h Wed Apr 24 17:39:30 2013 +0000
+++ b/mMotor.h Mon May 13 16:19:54 2013 +0000
@@ -20,9 +20,15 @@
mMotor(PinName M0, PinName M1, PinName M2, PinName M3); //motor constructor
+ /* Low Torque mode */
void step(int num_steps, int direction, int speed);
void counterclockwise();
void clockwise();
+
+ /* High Torque mode */
+ void ht_step(int num_steps, int direction, int speed);
+ void ht_counterclockwise();
+ void ht_clockwise();
private: