►Programming Full step Sequence

►C Programming
I am assuming that stepper motor is connected at Port 1.0 to Port 1.3. Adjusting the delay will increase or decrease the speed of the motor. Here just for demonstration i have taken some delay, you can change it as you want.

[Tip: Do testing.. ]




#include <REG2051.H>
.
#define stepper P1
void delay();

void main(){
	while(1){
		stepper = 0x0C;
		delay();
		stepper = 0x06;
		delay();
		stepper = 0x03;
		delay();
		stepper = 0x09;
		delay();
	}
}

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



►Assembly Programming

	org 0H

stepper equ P1

main:
	mov stepper, #0CH
	acall delay
	mov stepper, #06H
	acall delay
	mov stepper, #03H
	acall delay
	mov stepper, #09H
	acall delay
	sjmp main

delay:
	mov r7,#4
wait2:
	mov r6,#0FFH
wait1:
	mov r5,#0FFH
wait:
	djnz r5,wait
	djnz r6,wait1
	djnz r7,wait2
	ret
	end


The working of the above code can be seen in the demo animation below.

unipolar stepper motor in full step sequence


►Programming Half step Sequence

►C Programming
Just the main routine changes rest everything remains same, i mean same delay routine.


void main(){
	while(1){
		stepper = 0x08;
		delay();
		stepper = 0x0C;
		delay();
		stepper = 0x04;
		delay();
		stepper = 0x06;
		delay();
		stepper = 0x02;
		delay();
		stepper = 0x03;
		delay();
		stepper = 0x01;
		delay();
		stepper = 0x09;
		delay();
	}
}



►Assembly Programming
Here also the main routine changes rest everything remains same.


main:
	mov stepper, #08H
	acall delay
	mov stepper, #0CH
	acall delay
	mov stepper, #04H
	acall delay
	mov stepper, #06H
	acall delay
	mov stepper, #02H
	acall delay
	mov stepper, #03H
	acall delay
	mov stepper, #01H
	acall delay
	mov stepper, #09H
	acall delay
	sjmp main


The working of the above code can be seen in the demo animation below.

unipolar stepper motor in half step sequence


►Programming for 2-wire connection of Unipolar Stepper Motor

►C Programming
void main(){
	while(1){
		stepper = 0x03;
		delay();
		stepper = 0x01;
		delay();
		stepper = 0x00;
		delay();
		stepper = 0x02;
		delay();
	}
}



►Assembly Programming
main:
	mov stepper, #03H
	acall delay
	mov stepper, #01H
	acall delay
	mov stepper, #00H
	acall delay
	mov stepper, #02H
	acall delay
	sjmp main


The working of the above code can be seen in the demo animation below.

unipolar stepper motor in 2-wire connection mode


►Programming for Bipolar Stepper Motor

►C Programming
void main(){
	while(1){
		stepper = 0x08;
		delay();
		stepper = 0x02;
		delay();
		stepper = 0x04;
		delay();
		stepper = 0x01;
		delay();
	}
}



►Assembly Programming
main:
	mov stepper, #08H
	acall delay
	mov stepper, #02H
	acall delay
	mov stepper, #04H
	acall delay
	mov stepper, #01H
	acall delay
	sjmp main



Now you're ready to use stepper motors. If you have any doubts, please post in the forum.

◄ Previous Page  |  Next Page ►

Back to main


DC Motor Tutorial Index
Introduction to Stepper Motors
Stepper Motor Connections
Step Sequence of Stepper Motors
Programming for Stepper Motor

Conversation

Fri Jan 23 2015, 04:29 AM
lolokijuh
DJ Bakal tulungan mo ako s IC Tester
Fri Jan 23 2015, 04:29 AM
lolokijuh
sir help about IC Tester
Fri Jan 23 2015, 04:28 AM
lolokijuh
sir help me
Thu Jan 22 2015, 08:27 PM
1
-1'
Thu Jan 22 2015, 08:27 PM
1
1
Thu Jan 22 2015, 01:59 PM
apparao majji
could you please help in programming
Thu Jan 22 2015, 10:13 AM
avianash
hi my account is inactive plz help me
gaurav.k
Thu Jan 22 2015, 07:04 AM
not able top post any reply from my login... after pressing "post Reply "it takes me to a blank page
Thu Jan 22 2015, 04:06 AM
frankie
friend, that modification should be done in the program so that led up and down oscillation is one blink, thanks
Wed Jan 21 2015, 07:16 PM
1
-1'

Downloads

Comments

nawfel
Sat Jan 17 2015, 07:27 AM
Rohi123
Sat Jan 10 2015, 11:00 AM
safakarici
Fri Jan 09 2015, 08:55 PM
Nikita_Pinjare
Thu Jan 08 2015, 03:10 PM
mayank058
Wed Jan 07 2015, 05:43 AM
Overeating
Tue Jan 06 2015, 05:56 AM
trancebreaker11
Sun Jan 04 2015, 07:42 AM
akash474001
Thu Jan 01 2015, 05:49 AM

Online

Guests: 41, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37573
Newest member: nawfel
Forum Activity
mayank058 Avatar
Posted By mayank058
Thu Jan 22 2015, 12:16 PM
dear sir, Now i want to generate a si...
mayank058 Avatar
Posted By mayank058
Tue Jan 20 2015, 06:40 AM
dear sir, Now its working properly. Th...
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Jan 20 2015, 04:36 AM
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Jan 20 2015, 04:35 AM
I found another issue with your code:calling PWMIn...
mayank058 Avatar
Posted By mayank058
Mon Jan 19 2015, 05:47 AM
dear sir, Please do it for me..
PsySc0rpi0n Avatar
Posted By PsySc0rpi0n
Sun Jan 18 2015, 08:23 PM
But it's a way to debug to consider to the future ...
ajay_bhargav Avatar
Posted By ajay_bhargav
Sun Jan 18 2015, 06:04 AM
I remember i created small library for lpc23xx ser...
ajay_bhargav Avatar
Posted By ajay_bhargav
Sun Jan 18 2015, 06:00 AM
It's obviously a personal choice. Digging into map...
ajay_bhargav Avatar
Posted By ajay_bhargav
Sun Jan 18 2015, 05:58 AM
@karan123 I suggest you to create a new thread for...
mayank058 Avatar
Posted By mayank058
Fri Jan 16 2015, 06:55 AM
dear sir, I used all these methods.. w...