Stepper motor control class library
Dependents: StepperMotor_HelloWorld
Components pages
Components pages are available for bipolar and unipolar motor libraries
Diff: StepperMotor.cpp
- Revision:
- 1:dc6cf8f8bcb7
- Parent:
- 0:4beb37ae37ce
- Child:
- 2:f14b5e7276b0
diff -r 4beb37ae37ce -r dc6cf8f8bcb7 StepperMotor.cpp
--- a/StepperMotor.cpp Thu Nov 25 11:11:51 2010 +0000
+++ b/StepperMotor.cpp Fri Nov 26 15:32:25 2010 +0000
@@ -1,3 +1,15 @@
+/** Stepper Motor control library
+ *
+ * @class StepperMotor
+ * @author Tedd OKANO
+ * @version 0.51(27-Nov-2010)
+ *
+ * Copyright: 2010 Tedd OKANO, Tsukimidai Communications Syndicate - Crawl Design
+ * The library that controls stepper motor via motor driver chip: TA7774
+ * The TA7774 is a driver for a bipolar stepper motor.
+ * With this library, mbed will generate 2 phase pulses to operate the motor.
+ */
+
#include "mbed.h"
#include "StepperMotor.h"
@@ -25,8 +37,8 @@
t.attach( this, &StepperMotor::motor_maintain, 1.0 / (float)pps );
}
-int StepperMotor::set_pps( int v ) {
- int p;
+float StepperMotor::set_pps( float v ) {
+ float p;
p = pps;
pps = v;
@@ -35,14 +47,14 @@
return ( p );
}
-void StepperMotor::set_max_pps( int v ) {
+void StepperMotor::set_max_pps( float v ) {
max_pps = v;
}
int StepperMotor::find_home_position( PositionDetectPorarity edge ) {
RotMode prev_rot;
SyncMode prev_sync;
- int prev_pps;
+ float prev_pps;
int prev_det_pin;
int direction;
@@ -131,8 +143,9 @@
}
void StepperMotor::set_target_pos( int p ) {
- target_pos = (p + max_pos) % max_pos;
-
+ p = p % max_pos;
+ target_pos = (p < 0) ? (p + max_pos) : p;
+
if (sync_mode == SYNCHRONOUS)
while ( distance() )
wait( 0 );