please help controlling of a servo motor with 8051 ( incrementing its angle by 5 )

anikdas

Jan 6, 2013
7
Joined
Jan 6, 2013
Messages
7
hallo guys
I want to control a servo motor with 8051 microcontroller and to increment its angle by 5 degree and when its reach then after its get to 180 degree it will agian decrement its angle by 5 degree and reach to zero ..
in proteus simulation its not happenig and stucked to 90..

i am attaching the proteus simulation where u can get the circuit that i am using and i am aslo attaching the keil zip file where u can get the c code

please guys help me

u can also double click on the servo motor in proteus and make its maximum degree to 180 ..then it will get stuck to 180 degree
please anyone help me
 

Attachments

  • KEIL HEX CODE.zip
    26 KB · Views: 177
  • PROTEUS SIMULATION.zip
    31.5 KB · Views: 132

davenn

Moderator
Sep 5, 2009
14,470
Joined
Sep 5, 2009
Messages
14,470
PLEASE DONT multi post the same topic!!

Dave
 

donkey

Feb 26, 2011
1,301
Joined
Feb 26, 2011
Messages
1,301
ok just for me I thought I would let you know, I will never download zip files its just too risky.
you can however go to the advanced text chat and paste code there for us to read. as for the other zip still not going to download it
 

anikdas

Jan 6, 2013
7
Joined
Jan 6, 2013
Messages
7
// Program to rotate servo by 5 degree from previous position starting from 0 degree

// 0 degree = 700us
// 180 degree = 5500us
// Timer1 pulse after 50us -23

#include<reg51.h>
sbit output=P1^0; //Output to motor
int count;

void delay(unsigned int msec) // Function for delay
{
int i,j;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}

void timer(int msec) // Function for timer
{
int i;
TR1=1;
for(i=0;i<msec;i++)
{
while(TF1==0);
TF1=0;
}
TR1=0;
}
void main()
{
int i;
TMOD=0x20; // Mode2
TH1= -23; // 50usec timer
output=0;
count=14;
while(1)
{
if(count>=100)
count=14;
else
count=count+5;
for(i=0;i<200;i++)
{
output=1;
timer(count);
output=0;
timer(360);
}
delay(100);
}
}


the code is like this
 

anikdas

Jan 6, 2013
7
Joined
Jan 6, 2013
Messages
7
the circuit i am using is like this

the circuit
 

Attachments

  • circuit1.jpg
    circuit1.jpg
    54.4 KB · Views: 424

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Have you tested your code module by module? (for example do you know that your delay actually delays the correct amount?)

Have you looked at the signal going to the servo when a fixed angle is selected to confirm that it has the correct mark/space ratio, amplitude, etc.?

Please don't dump the whole thing in our lap with an "it doesn't work". Telling us what you've tested already would be extremely helpful (lest we simply waste time asking you to do it again).
 

anikdas

Jan 6, 2013
7
Joined
Jan 6, 2013
Messages
7
no i havnot done that..i dont know how to do that,,, can u please tell me how toplease
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Well, firstly, perhaps you can write a program using your delay routine to flash a LED 1 second on, 1 second off...

If you do that, you'll be able to check with a watch that the timing is reasonably correct. If it stays in time over a minute, the error is less than 2%.

Then you might choose to set it to 5 ms on/5 ms off and using your current circuit look at the output on an oscilloscope. Is the timing still correct? What does the waveform look like (is it a rail to rail square wave?)

Now manually set the mark/space ration to whatever you expect will turn the servo to some predetermined angle. Does it work? Does the waveform still look correct when connected to the servo?

Now change the program so it only outputs the waveform while the button is pressed.

Keep going.

The process is called stepwise refinement. You start with something simple that you can understand as a unit and is easily testable without having too many unknowns. You then refine the process to add features which get it closer and closer to your final solution, each time making an incremental change that can be tested and shown to work.

It helps if you have a plan as to how your program will work, because this process can start with testing your low level routines, moving up a level each time you are confident that layer is working.
 
Top