Updated stepper motor controller
Fork of StepperController by
Revision 1:6e8186dd5bfa, committed 2018-06-08
- Comitter:
- acracan
- Date:
- Fri Jun 08 08:05:29 2018 +0000
- Parent:
- 0:2cfd64d210f3
- Child:
- 2:d589fc047bc9
- Commit message:
- Add different types of sequencing
Changed in this revision
steppercontroller.cpp | Show annotated file Show diff for this revision Revisions of this file |
steppercontroller.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/steppercontroller.cpp Mon Jun 29 07:47:45 2015 +0000 +++ b/steppercontroller.cpp Fri Jun 08 08:05:29 2018 +0000 @@ -1,4 +1,3 @@ - #include "steppercontroller.h" StepperController::StepperController(PinName phaseA,PinName enA, PinName phaseB, PinName enB ): @@ -32,6 +31,11 @@ this->dir = dir; } +void StepperController::setSequenceType(SequenceType seq) +{ + this->seq = seq; +} + void StepperController::updateOutputs() { switch(state){ @@ -42,24 +46,44 @@ enB = 0.0f; break; case 1: - phaseA = 0; - enA = pulseWidth; - phaseB = 0; - enB = 0.0f; + switch(seq) { + case Consecutive: + phaseA = 0; + enA = pulseWidth; + phaseB = 0; + enB = 0.0f; + break; + case Interleaved: + phaseA = 0; + enA = 0.0f; + phaseB = 1; + enB = pulseWidth; + break; + } break; case 2: - phaseA = 0; - enA = 0.0f; - phaseB = 1; - enB = pulseWidth; + switch(seq) { + case Consecutive: + phaseA = 0; + enA = 0.0f; + phaseB = 1; + enB = pulseWidth; + break; + case Interleaved: + phaseA = 0; + enA = pulseWidth; + phaseB = 0; + enB = 0.0f; + break; + } break; case 3: - phaseA = 0; - enA = 0.0f; - phaseB = 0; - enB = pulseWidth; + phaseA = 0; + enA = 0.0f; + phaseB = 0; + enB = pulseWidth; break; default: @@ -68,10 +92,4 @@ phaseB = 0; enB = 0.0; } -} - - - - - - \ No newline at end of file +} \ No newline at end of file
--- a/steppercontroller.h Mon Jun 29 07:47:45 2015 +0000 +++ b/steppercontroller.h Fri Jun 08 08:05:29 2018 +0000 @@ -6,11 +6,13 @@ public: enum Direction {DirectionCW = 1, DirectionCCW = -1}; + enum SequenceType {Consecutive, Interleaved}; StepperController(PinName phaseA,PinName enA, PinName phaseB, PinName enB ); void advance(); void setPeriod(float period); void setPulseWidth(float width); void setDirection(Direction dir); + void setSequenceType(SequenceType seq); private: int state; @@ -18,9 +20,10 @@ DigitalOut phaseA, phaseB; PwmOut enA, enB; Direction dir; + SequenceType seq; void updateOutputs(); }; - #endif \ No newline at end of file +#endif \ No newline at end of file