Stepper motor control using MOTOR-1 Peripheral Board


Simple example which shows how to control MOTOR-1 peripheral board.

Toolkit:SDCC 8051 Development System

Location:/bipom/devtools/SDCC/examples/motor1/

Code Example


-------- HARDWARE DESCRIPTION -------------------------------------------------

//.....Configure Motor Enable Output ......

#define Motor_EN  P3_2  
// JP3 			- Installed

// JP4,JP5,JP16	- Not Installed

//

//.... Configure Motor Direction Output.....

#define Motor_DIR  P1_1  
// JP10 					- Installed

// JP11,JP12,JP13,JP14,JP15 - Not Installed

//

//....Configure Motor Step Output...........

#define Motor_STEP P3_5  
// JP6 			- Installed

// JP7,JP8,JP9	- Not Installed

//

//....Configure wave-drive format (TWO-PHASE DRIVE SEQUENSE)......

//Jumpers:   Half Step JP2 - Installed, Phase JP1 - Installed

//STEP		A		B		C		D

//RESET		ON	 	off	 	off   	ON

//

//	1		ON	 	off	 	off	 	ON

//  2   	ON   	off   	off   	off

//	3	 	ON	 	ON	   	off	 	off

//  4   	off  	ON    	off   	off			    

//	5		off	 	ON	   	ON	   	off

//  6   	off  	off   	ON    	off 

//	7		off	 	off		ON	   	ON

//  8   	off  	off   	off   	ON

//

//....Connections Stepper Motor Type 26MO48B2U to the MOTOR-1 board....

// OUT A  - YELLOW

// OUT B  - BLACK

// OUT C  - ORANGE

// OUT D  - BROWN

// COM    - RED,GREEN 

//

//....Calculating on the time (in mS) for half step ......

// motor speed : 1 rounds per one second

// Step Size on the Stepper motor  (deg) : 7.5

// Number steps on the motor for one round(360deg) = 360/7.5 = 48

// Total  number steps and half-steps for one round = 48*2=96 

// Time for one round = 1000/1 = 1000mS

// Time for half-step = 1000/96= 10.4mS (select 10mS ; 1.042 rounds rer second)  

//

//....Calculating the time for high and low status on 

// the Motor_STEP pin when 50% Pulse Width Modulation.................... 

// Speed = 10mS/2 = 5mS


#define Speed  			5
#define Steps_For_Round 96

void Motor_Round();

//--------------------- Loop of the Main Program ---------------------------------

void main()
{	
	while(5)
	{
  		Motor_DIR = 0;		// Setting direction '0' for rotating

	  	Motor_Round();    	// Calling function  for making one round

  		delay(1000<<1);   	// Delay time one second before change on the rotating direction 

	  	Motor_DIR = 1;		// Setting direction '1' for rotating  

  		Motor_Round();    	// Calling function  for making one round 

  		delay(1000<<1);   	// Delay time one second before change on the rotating direction   

  }	
}
//------------------ FUNCTION : MOTOR_ROUND ----------------------------------------

void Motor_Round()
{
	int CountStep;     	// Steps Counter 

	Motor_EN = 0; 			// Enabling motor driver

	for(CountStep=1; CountStep<Steps_For_Round; CountStep++)
	{
		Motor_STEP = 0;   	//Make step - change the phases status when negative edge  	 

		delay(Speed);   	//Delay  the half  time  from Half-Step time

		Motor_STEP = 1;   	//Preparing Motor_STEP output for the next step	  	

		delay(Speed);   	//Delay  the half  time  from Half-Step time		

	}
	
	Motor_EN = 1; 			//Disable motor driver

}