stepper motor unipolar half mode sla 7026/7033
Revision 0:3c13a1d67866, committed 2016-07-11
- Comitter:
- lego
- Date:
- Mon Jul 11 09:13:37 2016 +0000
- Commit message:
- sla7026/7033 unipolar stepper motor halfmode
Changed in this revision
STEPPER.cpp | Show annotated file Show diff for this revision Revisions of this file |
STEPPER.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/STEPPER.cpp Mon Jul 11 09:13:37 2016 +0000 @@ -0,0 +1,57 @@ +#include "mbed.h" +#include "STEPPER.h" + +STEPPER::STEPPER( +PinName a, PinName a_, PinName b, PinName b_, int dir +): + MotorPin(a, a_, b, b_) +{ + Direction = dir; + step_cw[0] = 0x9; + step_cw[1] = 0x8; + step_cw[2] = 0xa; + step_cw[3] = 0x2; + step_cw[4] = 0x6; + step_cw[5] = 0x4; + step_cw[6] = 0x5; + step_cw[7] = 0x1; + step_ccw[0] = 0x1; + step_ccw[1] = 0x5; + step_ccw[2] = 0x4; + step_ccw[3] = 0x6; + step_ccw[4] = 0x2; + step_ccw[5] = 0xa; + step_ccw[6] = 0x8; + step_ccw[7] = 0x9; + Speed = 1000; + count = 0; +} + +STEPPER::~STEPPER() +{ + //? +} + +void STEPPER::MotorStart() +{ + Motor.attach_us(this, &STEPPER::MotorControl,Speed); +} + +void STEPPER::MotorOff() +{ + Motor.detach(); + MotorPin = 0x0; +} + +void STEPPER::SetSpeed(int speed) +{ + Speed = speed; +} + +void STEPPER::MotorControl() +{ + count++; + if(count>7) count = 0; + if(Direction) MotorPin = step_ccw[count]; + else MotorPin = step_cw[count]; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/STEPPER.h Mon Jul 11 09:13:37 2016 +0000 @@ -0,0 +1,25 @@ +#include "mbed.h" +#define CCW 1 +#define CW 0 + +class STEPPER +{ + public: + STEPPER(PinName a, PinName a_, PinName b, PinName b_, int dir); + ~STEPPER(); + void MotorStart(); + void MotorOff(); + void SetSpeed(int speed); + void MotorControl(); + int step_cw[8]; + int step_ccw[8]; + int Speed; + int count; + int Direction; + + private: + BusOut MotorPin; + Ticker Motor; + + +}; \ No newline at end of file