Society of Robots - Robot Forum

Software => Software => Topic started by: Parth on June 07, 2008, 09:48:42 PM

Title: Code to Center Servos
Post by: Parth on June 07, 2008, 09:48:42 PM
I just have a quick question: does "Servo 0, 150" center a servo no matter how many degrees it can turn? For instance, if i had a servo that could rotate 200 degrees and a servo that could rotate 90 degrees, could I write the same code to center both of them? BTW this is for PICAXE. Thanks in advance!
Title: Re: Code to Center Servos
Post by: benji on June 08, 2008, 03:26:45 AM
check the servo specs

if it says pulse range from 1 to 2 ms then the center is 1.5 ms
so you provide a constant PWM signal of 1.5ms as logic HIGH and 20ms logic LOW

always make it the center of the pulse range
Title: Re: Code to Center Servos
Post by: Parth on June 08, 2008, 11:30:42 AM
OK, thanks! So, I have a question specifically for the Hitec HS-311. Would I write Servo 0, 150? I got this because it has a pulse width of 1-2, so 1.5 would be the middle, and I would write it as 150. Am I right?
Title: Re: Code to Center Servos
Post by: benji on June 08, 2008, 12:31:01 PM
this depends on how you are writing delays in your compiler
i never did use already made functions for servos

but lets do it this way

Code: [Select]
while(1)
{
PORTD.0=1;
delay_us(1500);
PORTD.0=0;
delay_ms(20);
}

i did use PORTD.0 as output (servo control pin)
and also you should include delay.h
Title: Re: Code to Center Servos
Post by: Parth on June 08, 2008, 05:34:59 PM
OK, thanks for all the help!  :)