hi I am using this code to drive servos with 8051 but my problem is that they are giving a kick and back to there place , below is my code . As one could see they suppose to turn to 78 degrees , but it is not working . Can someone pls help me figure out the problem ?
void timer(int msec) // Function to produce pulse as defined by user
{
int i;
TR1=1;
for(i=0;i<msec;i++)
{
if (TF1==0);
TF1=0;
}
TR1=0;
}
void servo()
{
{
int H;
TMOD=0x20; // MODE2
TH1= -23; // 50 usec timer
output=0;
msdelay(100);
count=0;
check=0;
digit[0]=8;
digit[1]=7;
digit[2]=0;
time=(digit[0]+(digit[1]*10)+(digit[2]*100));
time=time%180;
time= time*0.5; // (110-14)/180=0.53
for(H=0;H<200;H++)
{
output=1;
timer(14);
output=0;
timer(360);
}
msdelay(100);
for(H=0;H<200;H++)
{
output=1;
timer(time+14);
output=0;
timer(360);
}
timer(3000000);
}
}
void timer(int msec) // Function to produce pulse as defined by user
{
int i;
TR1=1;
for(i=0;i<msec;i++)
{
if (TF1==0);
TF1=0;
}
TR1=0;
}
void servo()
{
{
int H;
TMOD=0x20; // MODE2
TH1= -23; // 50 usec timer
output=0;
msdelay(100);
count=0;
check=0;
digit[0]=8;
digit[1]=7;
digit[2]=0;
time=(digit[0]+(digit[1]*10)+(digit[2]*100));
time=time%180;
time= time*0.5; // (110-14)/180=0.53
for(H=0;H<200;H++)
{
output=1;
timer(14);
output=0;
timer(360);
}
msdelay(100);
for(H=0;H<200;H++)
{
output=1;
timer(time+14);
output=0;
timer(360);
}
timer(3000000);
}
}