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.
StepperMotorUni Class Reference
Stepper Motor (Unipolar) control library. More...
#include <StepperMotorUni.h>
Public Types | |
| enum | OperationMode { STEP, HALFSTEP } |
Constants for motor rotate mode. More... | |
| enum | RotMode { CLOCKWISE, COUNTER_CLOCKWISE } |
Constants for motor rotate mode. More... | |
| enum | SyncMode { ASYNCHRONOUS, SYNCHRONOUS } |
Constants for syncronization mode. More... | |
Public Member Functions | |
| StepperMotorUni (PinName out_A, PinName out_B, PinName out_C, PinName out_D) | |
| Create a stepper motor object connected to specified DigitalOut pins and a DigitalIn pin. | |
| void | send_sequence (int stepPos) |
| Sends Sequence to turn motor. | |
| void | set_operation_mode (OperationMode v) |
| Set Stepper operation mode. | |
| void | rotate_angle (RotMode StMotorDirection, int Angle, float Speed) |
| Rotate motor at specified angle with given speed. | |
| void | rotate_steps (RotMode StMotorDirection, int Steps, float Speed) |
| Rotate motor with given steps with given time. | |
| void | set_sync_mode (SyncMode m) |
| Interface for syncronization mode setting. | |
| int | distance (void) |
| Check remaining distance that motor need to move software can check if the motor action completed in asynchronous mode. | |
| void | set_pause (int sw) |
| Pause/Resume the motor action. | |
| void | stop (void) |
| Stop motor and reset values to default. | |
Detailed Description
Stepper Motor (Unipolar) control library.
- Version:
- 1.0
- Date:
- 1-Feb-2016
The library that controls stepper motor via motor driver chip This is a driver for a unipolar stepper motor.
Example:
#include "mbed.h" #include "StepperMotorUni.h" StepperMotorUni motor( p26, p25, p24, p23 ); int main() { motor.set_operation_mode(StepperMotorUni::STEP); while ( 1 ) { motor.rotate_angle(StepperMotorUni::CLOCKWISE,90,0.02); wait( 1 ); motor.rotate_angle(StepperMotorUni::COUNTER_CLOCKWISE,90,0.02); wait( 1 ); } }
Definition at line 53 of file StepperMotorUni.h.
Member Enumeration Documentation
| enum OperationMode |
Constants for motor rotate mode.
Definition at line 58 of file StepperMotorUni.h.
| enum RotMode |
Constants for motor rotate mode.
Definition at line 64 of file StepperMotorUni.h.
| enum SyncMode |
Constants for syncronization mode.
- Enumerator:
ASYNCHRONOUS program does wait motor turn completion (default)
SYNCHRONOUS program doesn't wait motor turn completion
Definition at line 70 of file StepperMotorUni.h.
Constructor & Destructor Documentation
| StepperMotorUni | ( | PinName | out_A, |
| PinName | out_B, | ||
| PinName | out_C, | ||
| PinName | out_D | ||
| ) |
Create a stepper motor object connected to specified DigitalOut pins and a DigitalIn pin.
- Parameters:
-
out_A DigitalOut pin for motor pulse signal-A out_B DigitalOut pin for motor pulse signal-B out_C DigitalOut pin for motor pulse signal-C out_D DigitalOut pin for motor pulse signal-D
Definition at line 37 of file StepperMotorUni.cpp.
Member Function Documentation
| int distance | ( | void | ) |
Check remaining distance that motor need to move software can check if the motor action completed in asynchronous mode.
- Returns:
- remaining steps that motor need to go
Definition at line 92 of file StepperMotorUni.cpp.
| void rotate_angle | ( | RotMode | StMotorDirection, |
| int | Angle, | ||
| float | Speed | ||
| ) |
Rotate motor at specified angle with given speed.
- Parameters:
-
StMotorDirection Sets motor direction - CLOCKWISE
- COUNTER_CLOCKWISE
Angle Specify rotation angle Speed Specify Speed in Millisecond Per Step 50msps = 0.050 (It will take 50ms for 1 step)
Calculations: Move 360 degrees in 2 seconds
operation mode = STEP operation mode = HALFSTEP Time (in ms) speed = ------------------------ degrees/deg_per_step
2000 2000 2000 2000 speed =-------= ----= 10 = 0.010msps speed =-------=----= 5 = 0.005msps 360/1.8 200 360/0.9 400
Definition at line 119 of file StepperMotorUni.cpp.
| void rotate_steps | ( | RotMode | StMotorDirection, |
| int | Steps, | ||
| float | Speed | ||
| ) |
Rotate motor with given steps with given time.
- Parameters:
-
StMotorDirection Sets motor direction - CLOCKWISE
- COUNTER_CLOCKWISE
Steps Specify Steps to rotate Speed Specify Speed in Millisecond Per Step 50msps = 0.050 (It will take 50ms for 1 step)
Calculations: Move 200 steps in 2 seconds Time (in ms) 2000 speed = -------------= ------ = 10 = 0.010msps Steps 200
Definition at line 158 of file StepperMotorUni.cpp.
| void send_sequence | ( | int | stepPos ) |
Sends Sequence to turn motor.
- Parameters:
-
stepPos pattern index value/ sequence number
Definition at line 77 of file StepperMotorUni.cpp.
| void set_operation_mode | ( | OperationMode | v ) |
Set Stepper operation mode.
- Parameters:
-
v - STEP Single Step operation
- HALFSTEP Half Step operation
Definition at line 82 of file StepperMotorUni.cpp.
| void set_pause | ( | int | sw ) |
Pause/Resume the motor action.
- Parameters:
-
sw use "true" for pause, "false" (default) for resume
Definition at line 106 of file StepperMotorUni.cpp.
| void set_sync_mode | ( | SyncMode | m ) |
Interface for syncronization mode setting.
Example:
StepperMotor m( p21, p22, p23, p24 );
int main() {
m.set_sync_mode( StepperMotor::SYNCHRONOUS );
...
- Parameters:
-
m motor rotate mode : ASYNCHRONOUS (default) or SYNCHRONOUS
Definition at line 87 of file StepperMotorUni.cpp.
| void stop | ( | void | ) |
Stop motor and reset values to default.
Definition at line 111 of file StepperMotorUni.cpp.
Generated on Sat Jul 16 2022 01:20:43 by
1.7.2