Stepper_Motor

Stepper_Motor Library

Stepper Motor Library This library is very useful and can interface 4 coil stepper motor with all microcontrollers. And this library can control 4 motors simultaneously, also this library supports Mmagic_Sensor_Hook() in project main file. This Allow to control a variety of stepper motors in MikroStudio. This library allows you to control unipolar or bipolar stepper motors. To use it you will need a stepper motor, and the appropriate hardware to control it. Like ULN2xxx or L293d or any unipolar or bipolar stepper motor driver etc..

How to define pins in MikroStudio for Stepper motor library.

//To define the count of total motors if there is more than one
//#define Stepper_2Motor // for 2 Motors   
//#define Stepper_3Motor // for 3 Motors   
#define Stepper_4Motor   // for 4 Motors

#define M1_Coil_A P2,0  // Motor 1 Coil A @ P2, BIT0
#define M1_Coil_B P2,1  // Motor 1 Coil B @ P2, BIT1
#define M1_Coil_C P2,2  // Motor 1 Coil C @ P2, BIT2
#define M1_Coil_D P2,3  // Motor 1 Coil D @ P2, BIT3

#define M2_Coil_A P2,4  // Motor 2 Coil A @ P2, BIT4
#define M2_Coil_B P2,5  // Motor 2 Coil B @ P2, BIT5
#define M2_Coil_C P2,6  // Motor 2 Coil C @ P2, BIT6
#define M2_Coil_D P2,7  // Motor 2 Coil D @ P2, BIT7

#define M3_Coil_A P0,4  // Motor 3 Coil A @ P0, BIT4
#define M3_Coil_B P0,5  // Motor 3 Coil B @ P0, BIT5
#define M3_Coil_C P0,6  // Motor 3 Coil C @ P0, BIT6
#define M3_Coil_D P0,7  // Motor 3 Coil D @ P0, BIT7

#define M4_Coil_A P0,0  // Motor 4 Coil A @ P0, BIT0
#define M4_Coil_B P0,1  // Motor 4 Coil B @ P0, BIT1
#define M4_Coil_C P0,2  // Motor 4 Coil C @ P0, BIT2
#define M4_Coil_D P0,3  // Motor 4 Coil D @ P0, BIT3

Following functions can be used by this library.
void Stepper_Motor1_Init(void); //initializing motor 1
void Stepper_Motor1_Right(int ,long); //Motor 1 Turn Right(Step, delay)
void Stepper_Motor1_Left(int ,long); //Motor 1 Turn Left(Step, delay)

void Stepper_Motor2_Init(void); //initializing motor 2
void Stepper_Motor2_Right(int ,long); //Motor 2 Turn Right(Step, delay)
void Stepper_Motor2_Left(int ,long); //Motor 2 Turn Left(Step, delay)

void Stepper_Motor3_Init(void); //initializing motor 3
void Stepper_Motor3_Right(int ,long); //Motor 3 Turn Right(Step, delay)
void Stepper_Motor3_Left(int ,long); //Motor 3 Turn Left(Step, delay)

void Stepper_Motor4_Init(void); //initializing motor 4
void Stepper_Motor4_Right(int ,long); //Motor 4 Turn Right(Step, delay)
void Stepper_Motor4_Left(int ,long); //Motor 3 Turn Left(Step, delay)

void Stepper_Motor1_And_2_Join_Left(int, long); //Turn Left Motor 1 and 2 together(Step, delay)
void Stepper_Motor1_And_2_Join_Right(int, long); //Turn Right Motor 1 and 2 together(Step, delay)

void Stepper_Motor1_And_3_Join_Right(int, long); //Turn Right Motor 1 and 3 together(Step, delay)
void Stepper_Motor2_And_3_Join_Right(int, long); //Turn Right Motor 2 and 3 together(Step, delay)
void Stepper_Motor1_And_3_Join_Left(int, long); //Turn Left Motor 1 and 3 together(Step, delay)
void Stepper_Motor2_And_3_Join_Left(int, long); //Turn Left Motor 2 and 3 together(Step, delay)

void Stepper_Motor1_And_4_Join_Right(int, long); //Turn Right Motor 1 and 4 together(Step, delay)
void Stepper_Motor2_And_4_Join_Right(int, long); //Turn Right Motor 2 and 4 together(Step, delay)
void Stepper_Motor3_And_4_Join_Right(int, long); //Turn Right Motor 3 and 4 together(Step, delay)
void Stepper_Motor1_And_4_Join_Left(int, long); //Turn Left Motor 1 and 4 together(Step, delay)
void Stepper_Motor2_And_4_Join_Left(int, long); //Turn Left Motor 2 and 4 together(Step, delay)
void Stepper_Motor3_And_4_Join_Left(int, long); //Turn Left Motor 3 and 4 together(Step, delay)
Global variables:

For endless rotation, if this variable is true then the motor runs endless loop (will auto reload  at given step and delay) and if it is false then the function normal works as given (step and delay). 

bool Stepper_Auto_Reload = false; // if true then motors rotate like endless (auto reload step , delay)

Admin
Author: Admin

Leave a Reply