|
PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
Go to the documentation of this file.
52 static const Step DEFAULT_START_STEP = Step::HALF;
65 const Pin::Mask phase4Mask,
const Step start = DEFAULT_START_STEP)
66 : m_currentStep(start),
67 m_phase1(phase1Mask,
Pin::Dir::OUT),
68 m_phase2(phase2Mask,
Pin::Dir::OUT),
69 m_phase3(phase3Mask,
Pin::Dir::OUT),
70 m_phase4(phase4Mask,
Pin::Dir::OUT) {
80 this->m_currentStep = step;
89 return this->m_currentStep;
102 const bool movementNeeded =
static_cast<bool>(
static_cast<uint32_t
>(this->m_currentStep) % 2);
103 if (movementNeeded) {
109 return movementNeeded;
122 const bool movementNeeded = !
static_cast<bool>(
static_cast<uint32_t
>(this->m_currentStep) % 2);
123 if (movementNeeded) {
129 return movementNeeded;
140 const unsigned int stepNumber =
static_cast<unsigned int>(this->m_currentStep) + 2;
141 this->m_currentStep =
static_cast<Step
>(stepNumber % 8);
154 while (halfSteps--) {
155 const unsigned int stepNumber =
static_cast<unsigned int>(this->m_currentStep) + 1;
156 this->m_currentStep =
static_cast<Step
>(stepNumber % 8);
170 const unsigned int stepNumber =
static_cast<unsigned int>(this->m_currentStep) + 6;
171 this->m_currentStep =
static_cast<Step
>(stepNumber % 8);
184 while (halfSteps--) {
185 const unsigned int stepNumber =
static_cast<unsigned int>(this->m_currentStep) + 7;
186 this->m_currentStep =
static_cast<Step
>(stepNumber % 8);
196 virtual void rotate () {
197 switch (this->m_currentStep) {
199 this->m_phase1.
set();
200 this->m_phase2.
clear();
201 this->m_phase3.
clear();
202 this->m_phase4.
set();
205 this->m_phase1.
set();
206 this->m_phase2.
clear();
207 this->m_phase3.
clear();
208 this->m_phase4.
clear();
210 case Step::ONE_AND_A_HALF:
211 this->m_phase1.
set();
212 this->m_phase2.
set();
213 this->m_phase3.
clear();
214 this->m_phase4.
clear();
217 this->m_phase1.
clear();
218 this->m_phase2.
set();
219 this->m_phase3.
clear();
220 this->m_phase4.
clear();
222 case Step::TWO_AND_A_HALF:
223 this->m_phase1.
clear();
224 this->m_phase2.
set();
225 this->m_phase3.
set();
226 this->m_phase4.
clear();
229 this->m_phase1.
clear();
230 this->m_phase2.
clear();
231 this->m_phase3.
set();
232 this->m_phase4.
clear();
234 case Step::THREE_AND_A_HALF:
235 this->m_phase1.
clear();
236 this->m_phase2.
clear();
237 this->m_phase3.
set();
238 this->m_phase4.
set();
241 this->m_phase1.
clear();
242 this->m_phase2.
clear();
243 this->m_phase3.
clear();
244 this->m_phase4.
set();
void half_reverse(unsigned int halfSteps, const unsigned int usDelay=DEFAULT_DELAY)
Move the motor backward by a specified number of half-steps.
4-pin bipolar and 5-pin unipolar stepper motor driver
bool half_power_hold(const bool direction, const unsigned int usDelay=DEFAULT_DELAY)
Step the motor to the nearest full-step to achieve a half-power hold.
void step_to(const Stepper::Step step)
Move the motor directly to the specified step.
Utility class to handle general purpose I/O pins.
Stepper(const Pin::Mask phase1Mask, const Pin::Mask phase2Mask, const Pin::Mask phase3Mask, const Pin::Mask phase4Mask, const Step start=DEFAULT_START_STEP)
Constructor.
void set() const
Set selected output port high (set all pins to 1)
void step_forward(unsigned int steps, const unsigned int usDelay=DEFAULT_DELAY)
Move the motor forward by a specified number of steps.
bool full_power_hold(const bool direction, const unsigned int usDelay=DEFAULT_DELAY)
Step the motor to the nearest half-step to achieve a full-power hold.
Step get_current_step() const
Get the current step.
#define waitcnt(a)
Wait until system counter reaches a value.
#define CNT
The system clock count.
static const unsigned int DEFAULT_DELAY
Default delay in microseconds used between each step.
void half_forward(unsigned int halfSteps, const unsigned int usDelay=DEFAULT_DELAY)
Move the motor forward the a specified number of half-steps.
void step_reverse(unsigned int steps, const unsigned int usDelay=DEFAULT_DELAY)
Move the motor backward by a specified number of steps.
Generic definitions and functions for the Parallax Propeller.
void clear() const
Clear selected output port (set it to 0)