Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

c program for rotating stepper motor to particular angle in 8051 microcontroller

Status
Not open for further replies.

ankit_265

Newbie level 2
Joined
Mar 30, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,301
Sir, i am having stepper motor of 2 degree step angle.
I m using following c program:

#include<reg51.h>
void main()
{
while(1)
{ void delay (int);
P1=0xCC;
delay(1);
P1=0x66;
delay(1);
P1=0x33;
delay(1);
P1=0x99;
delay(1);
}
}
void delay(int a)
{
unsigned int x,y;
for(x=0;x<10;x++)
for(y=0;y<a;a++);
}


But i want to rotate it to 80 degree only. I want to stop motor at 80 degree.
Please give me the c program for this....??
 

If it steps 2 degree and you want 80 degree then 2 * 40 = 80. Use a counter and count from 1 to 40 and stop the execution of motor code if count is > 40. i.e., put you motor code inside if(cnt <= 40) and before that initialize cnt to 1.
 

thank u for your valuable reply.....
bt m having problem for increasing the speed of rotation, I am using following code for delay :

void delay(int a)
{
for(i=0;i<1275;i++)
for(j=0;j<a:j++);
}

But when i am putting minimum value of a i.e. a=1, then i m getting the speed of 5.5 rpm.....
So please tell me how can i increase the speed of rotation more than 20 rpm
 

thank you very much.it was really helpful for me also.you mean put the the stepper sequence within a for loop..right????
 

What are the controls are there in stepper driver?
if u wanr to do any other work while running stepper u can follow this one.
if it have clock/pulse then use timer to genrate pulse and use one count and check for 80 and toggle pin which is connected to driver pulse/clock.after it reach to 80 stop timer to stop pulse or use any condition to to stop pulses.
80 count is taken beacuase it will give 50% duty cycle.
 

IF I AM USING SEPARATE FUNCTION FOR ROTATING AND IF I WANT TO COUNT THE STEP,THEN WHERE SHALL I USE COUNTER?IN THE FUNCTION OR IN THE ACCESSED PART?
//HERE
CLOCK();
OR
//CLOCK()
P0=0xCC;

AND I WANT TO DENOTE THE POSITION OF STEPER MOTOR ACCORDING TO THE COUNTER LIKE AS BELOW
WHILE(1<=COUNT<=30
POSITION=1;
WHILE(31<=COUNT<=50)
POSITION=2;
HOW TO DO IN AT89C51 IN C
 

use clock pulses in interrupt isr keep moderate freq. and use counter in isr only.
what are input to.stepper driver?
 

port 2.1,p2.2,2.3,2.4
isr means??
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top