go_away

Author Topic: Code to Center Servos  (Read 1608 times)

0 Members and 1 Guest are viewing this topic.

Offline ParthTopic starter

  • Full Member
  • ***
  • Posts: 71
  • Helpful? 0
Code to Center Servos
« 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!

Offline benji

  • Supreme Robot
  • *****
  • Posts: 832
  • Helpful? 0
Re: Code to Center Servos
« Reply #1 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
good ol' BeNNy

Offline ParthTopic starter

  • Full Member
  • ***
  • Posts: 71
  • Helpful? 0
Re: Code to Center Servos
« Reply #2 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?
« Last Edit: June 08, 2008, 11:34:27 AM by Parth »

Offline benji

  • Supreme Robot
  • *****
  • Posts: 832
  • Helpful? 0
Re: Code to Center Servos
« Reply #3 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
good ol' BeNNy

Offline ParthTopic starter

  • Full Member
  • ***
  • Posts: 71
  • Helpful? 0
Re: Code to Center Servos
« Reply #4 on: June 08, 2008, 05:34:59 PM »
OK, thanks for all the help!  :)

 


Get Your Ad Here

data_list