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.
Fork of StepperController by
steppercontroller.cpp
- Committer:
- acracan
- Date:
- 2018-06-15
- Revision:
- 2:d589fc047bc9
- Parent:
- 1:6e8186dd5bfa
File content as of revision 2:d589fc047bc9:
#include "steppercontroller.h"
StepperController::StepperController(PinName phaseA,PinName enA, PinName phaseB, PinName enB ):
phaseA(phaseA), enA(enA), phaseB(phaseB), enB(enB)
{
this->enA.period(50e-6f);
this->enB.period(50e-6f);
pulseWidth = 0.1f;
state = 0;
seq = Interleaved;
}
void StepperController::advance()
{
state = (state + 4 + dir) & 3;
updateOutputs();
}
void StepperController::setPeriod(float period)
{
enA.period(period);
enB.period(period);
}
void StepperController::setPulseWidth(float pulseWidth)
{
this->pulseWidth = pulseWidth;
}
void StepperController::setDirection(Direction dir)
{
this->dir = dir;
}
void StepperController::setSequenceType(SequenceType seq)
{
this->seq = seq;
}
void StepperController::updateOutputs()
{
switch(state){
case 0:
phaseA = 1;
enA = pulseWidth;
phaseB = 0;
enB = 0.0f;
break;
case 1:
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:
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;
break;
default:
phaseA = 0;
enA = 0.0;
phaseB = 0;
enB = 0.0;
}
}
