[SOLVED] Stepper motor sequence for microcontroller.

Status
Not open for further replies.

0killingsoul0

Junior Member level 2
Joined
Feb 8, 2012
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,432
I have a dc stepper motor with six wires. Two for dc input of 12 volts and other two A,B,C,D for stepping sequence. The motor step angle is 1.8 degree. I want to rotate it with 200 steps in one complete rotation(360 degree). Can some one devise/tell me the stepping sequence i should use. ?? I am using 8051 microcontroller.
 

the sequence is as follows for full step:
ABCD
1000
0100
0010
0001

apply the sequence to the correct winding .
 

the sequence is as follows for full step:
ABCD
1000
0100
0010
0001

apply the sequence to the correct winding .



Code:
#include<reg51.h>
#define stepper P1

unsigned int d;

unsigned int mysequence[]=  {	 
	   
	   
	   0x8,0x4,0x2 ,0x1 ,
	   0x8,0x4,0x2 ,0x1 ,
	   0x8,0x4,0x2 ,0x1 ,
	   0x8,0x4,0x2 ,0x1 ,
	   0x8,0x4,0x2 ,0x1 ,
	   0x8,0x4,0x2 ,0x1 ,
	   0x8,0x4,0x2 ,0x1 ,
	   0x8,0x4,0x2 ,0x1 ,
	   0x8,0x4,0x2 ,0x1 ,
	   0x8,0x4,0x2 ,0x1 ,
	   0x8,0x4,0x2 ,0x1 ,
	   0x8,0x4,0x2 ,0x1 	

	   
	   
	   };	
		

void ex0_isr (void) interrupt 0
{
if (d<210)	
{
	d++;   // Increment the count
}
}


void ex1_isr (void) interrupt 2
{
	if (d>0)	
	{
			d--;

				}
	
    
}



void delay(){
        unsigned char i,j,k;
        for(i=0;i<0;i++)
                for(j=0;j<255;j++)
                        for(k=0;k<255;k++);
}

void main()


{

	  IT0 = 1;   // Configure interrupt 0 for falling edge on /INT0 (P3.2)
	  IT1 = 1;   // Configure interrupt 1 for falling edge on /INT0 (P3.2)
	  
	  
	  EX0 = 1;   // Enable EX0 Interrupt
      EX1 = 1;
	  
	  EA = 1;    // Enable Global Interrupt Flag

			   
	   

	 while(1)
	 
	 {
	   if(d==0)
	   {

	   }

	   else {
	   			 
				 stepper= d;
	 			 
			//	 stepper= mysequence[d];
	 			 delay();
			 }
	
	}
	
	
		
}



With your sequence its moving to and fro for about 6 d egrees. Not complete rotation. I need complete rotation with 200 steps.
 

first check your connection that A, B, C,D winding wires are properly identified with color codes from your motor data sheet.

if there is any change in winding connections , the above problem may be seen.

another one: for testing alone do not use interrupt and complicated test codes.

have a simple code like:

send sequence 0x8, 0x4, 0x2, 0x1.
to stepper motor one by one with a software delay in between .
send continuously the sequence one by one , repeating from the beginning to a prt and thro the drivers to motor..

see whether the motor rotates continuously in one direction.
this way you are sure that the motor is all right.
then you can test your final code with interrupts etc.
 
is there any way to identify motor wires in proteus? I did try with simple code but the problem is same there.
 

Hello!

1. Why do you write 12 times the same sequence in the array?
Why not using uint8 my sequence[] = {0x8,0x4,0x2 ,0x1};

2. What is the if(d < 210) line? Why 210?

3. In your main loop, you set stepper to d, not to mysequence[d].
What happens if d does not belong to mysequence? For instance if d = 3, you will
power 2 circuits at the same time and get a half step.

Now here is the solution I used recently (it was a 2 phase motor, but anyway):

1. Set a timer with a given interval.
2. On timer interrupt, increment the current position (your d variable).
if d > 3, set it back to 0. Therefore d will iterate 0, 1, 2, 3, 0, 1, 2, 3 ...
(you can use the same process for half steps by having a 8-step mysequence[] array)
like this: uint8 mysequence[]= {0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x09};

Now you can have an interrupt with a different device (I use serial port).
On serial port interrupt, you read the serial port message, and you can change
the delay (therefore the rotation speed), start / stop, set the number of steps, etc...

Dora.
 

Yaa I do agree with Dora....you don't need to write it 12 time also you can try this also
wire a b c d
step-1 1 1 0 0
step-2 0 1 1 0
step-3 0 0 1 1
step-4 1 0 0 1

good luck
 

It is a long time since I drove any stepper motors but the sequence for full stepping then was:

1100
0110
0011
1001

Keith
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…