Edutech IoT Team / StepperMotorUni
Embed: (wiki syntax)

« Back to documentation index

StepperMotorUni Class Reference

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.

Author:
Dwijay.Edutech Learning Solutions
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

Constants for motor rotate mode.

Enumerator:
STEP 

Single step operation (default)

HALFSTEP 

half step operation

Definition at line 58 of file StepperMotorUni.h.

enum RotMode

Constants for motor rotate mode.

Enumerator:
CLOCKWISE 

one-way: clockwise turn

COUNTER_CLOCKWISE 

one-way: counter clockwise turn

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_ADigitalOut pin for motor pulse signal-A
out_BDigitalOut pin for motor pulse signal-B
out_CDigitalOut pin for motor pulse signal-C
out_DDigitalOut 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:
StMotorDirectionSets motor direction

  • CLOCKWISE
  • COUNTER_CLOCKWISE
AngleSpecify rotation angle
SpeedSpecify 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:
StMotorDirectionSets motor direction

  • CLOCKWISE
  • COUNTER_CLOCKWISE
StepsSpecify Steps to rotate
SpeedSpecify 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:
stepPospattern 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:
swuse "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:
mmotor 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.