Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Basic Servo Motor doubt

Status
Not open for further replies.

puremobi

New Member
Hi,
I bought a Futuba s3003 servo
They say with 20ms delay and range b/w 1-2 ms u can control the rotation.
Should the PWN be continously sent to the motor?..
doubt: if i do,the motor continously rotates till mechanical limits.

i believe 1.5 ms is the mid position.

This is the CODE sample for 1.5 ms
when external input to 3.2 pin of 89c51 is given,i enable the servo..

======================================================
void main()
{
TMOD = 0x01;
TH0 = 0xB1;
TL0 = 0xE0;
EX0=1;
EA = 1;
ET0 = 1;
TR0 = 1;

if(P3_2 == 0)
{
void timer0_0();
}
}

void timer0_0 () interrupt 0
{
if(F0){
F0 = 0;
TH0 = 0xB1; // 20ms
TL0 = 0xE0;
P1_0 = 0;
TF0 = 0;
return;
}
else {
F0 = 1;
TH0 = 0xFA; // 1.5ms
TL0 = 0x24;
P1_0 = 1;
TF0 = 0;
return;
}
}

also i find one more issue..if 2ms is for counter clockwise..the servo still rotates in the same clk wise direction..
 
Last edited:
Yes, 1-2ms on, remainder of the 20ms off, sent continuously, 1.5ms is the center. If it runs to the limits, it means the timing is off. Are you using a 12mhz clock?
 
hi

hi,
firstly ,thank you very much for the reply...
No i am using 11.0592 MHz..
if i send the pulse continously,how does it stop at ,lets say 90 degrees?..
in my above code...it doesnt stop at 90 degrees.

can u pls clarify this point.." the timing is off"..
does it mean..a 0 pulse should be sent from the microcontroller at all time to the motor?

One more note: the seller told me ..its a 24ms servo..
 
Last edited:
At 11mhz looks like your code is going to deliver a 1.37ms pulse. Shorter pulses = clockwise, looking at the top of the servo, so it is going to be more clockwise. You need to reduce
TH0 = 0xFA; // 1.5ms
TL0 = 0x24;

Also, check the pulse on a scope. Make sure you are sending what you think you are sending.
 
hi,
i did a try..there is problem..the servo keeps goin to its limits..
this is the code
pls do check..
this is what happens
whenever i insert zero to pin 3.2(variable n)
the servo rotates ,else no rotation.
how can i make it specific..like a defined rotation of 90 degrees?..its not happening here..

==============
void main()
{
TMOD = 0x01;
TH0 = 0xB1;
TL0 = 0xE0;
EX0=1;
EA = 1;
ET0 = 1;
TR0 = 1;
=============
if(n== 0)
{

timer0_0();
}

}


void timer0_0 () interrupt 0
{

if(F0){
F0 = 0;
TH0 = 0xed; //20ms
TL0 = 0xff;
p = 0;
TF0 = 0;
return;
}
else {
F0 = 1;

TH0 = 0xFA; // 1.5ms
TL0 = 0x98;
p = 1;
TF0 = 0;
return;
}
}
 
Last edited:
I see the problem - you have to set up a condition for that port pin INSIDE the timer interrupt. Don't make the timer itself conditional, it just runs continuously.
Code:
void main()
{
TMOD = 0x01; 
TH0 = 0xB1;
TL0 = 0xE0;
EX0=1;
EA = 1;
ET0 = 1;
TR0 = 1;
void timer0_0();
}

void timer0_0 () interrupt 0
{
  if(F0){ 
    F0 = 0; 
    TH0 = 0xB1; // 20ms
    TL0 = 0xE0; 
    P1_0 = 0; 
    TF0 = 0; 
    return; 
  }
  else { 
    F0 = 1; 
    P1_0 = 1; 
    TF0 = 0;
    if(P3_2 == 0)
    {
      TH0 = 0xFA; // 1.5ms 
      TL0 = 0x24; 
    }
    else { 
      TH0 = 0xF8; // 2.0ms 
      TL0 = 0x31; 
    }
    return; 
  }
}

Like that. Also, use code tags and indent or I'll kill you.
 
Last edited:
haha..u cant kill me..but u can try..

Hi again,
I tried the code..this is exactly what happens
Whenever the P3.2 ==0 the servo rotates clockwise,if i give continous zero without a break,the servo rotates clockwise to its limits

there is no counter clockwise rotation(2ms)

am i really missin any basic points here?..will it move anti clockwise in this case(the code above)?

duffy, i have one more file,which mite interest you...pls check it out..
iam gonna get a new breadboard to out this stuff in a day or two..
thanks again..have fun!

=========================
the code in the file is meant to run 8 servos using 89c51.the eg code given inthat is to run the servo in clockwise n anticlockwise upto the extremities w/o any defined timing..i.e.it runs irregularly relative to the timer..
 

Attachments

  • Servo_0.1.zip
    15.6 KB · Views: 234
If P3.2 == 1, does the servo move at all?
 
Did you remove the conditional statement on the timer function call?
 
hi,
yes i had removed..
the timer runs continously.
i guess its supposed to run anti clockwise ..when 3.2 is 1..

what else could be the issue?..
 
If you have a scope, then check the output signal - it should be a pulse between 1mS and 2mS, repeated every 20mS or so (the 20mS doesn't need to be accurate, only the 1-2mS matters.
 
ok,
i will take it to my univ n check it up..only option i hav.
in keil,there is somethin called..logic view analyser..it shows waveforms from a port pin...any clue abt it?...
i was thinkin of switching to 12Mhz crystal...easy calculations perhaps..
 
Last edited:
Try switching these two TH0/TL0 around -

Code:
      TH0 = 0xFA; // 1.5ms 
      TL0 = 0x24; 
    }
    else { 
      TH0 = 0xF8; // 2.0ms 
      TL0 = 0x31;

If everything else is correct, it should at least turn clockwise when p3.2==1. See if that happens.
 
hi..
sry for the late..
i had tried interchanging..but it din work..it still went clockwise when P3.2 = 0.
i even tried the exact value wrt 11.0592 Mhz..
most prolly my univ opens 2mrw..i will check it up there..
there must be some issue with the 1-2 ms..
if any other options...pls lemme knw...
sam
 
Well, that should tell you something right there. If you did that, it should be loading the OTHER timing variable and P3.2 should work the opposite way.

Try this - remove the conditional statement (the "if" clause) so that it just executes one of the timing variables all the time. Now P3.2 shouldn't make any difference. See what happens.
 
suezmalik

HELLO,
How r u.
please send me your final year project with circuit diagram,layout and other details.
u can send me other projects also with full details.
BUT I MAY WANT PROJECTS NOW IMEDIATELY.

I U WILL SEND ME NOW I WILL BE SO SO MUCH TANK FULL TO YOU.

my other E-MAIL ID SUEZMALIK@yahoo.com
YOU may have to send me on my both the E-MAIL.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top