View previous topic :: View next topic |
Author |
Message |
407grup
Joined: 24 Jan 2010 Posts: 1
|
Servo Position Control Problem |
Posted: Sun Jan 24, 2010 7:01 am |
|
|
First of all, I don't know a lot about servos or CCS C programming.
I use 16F877A PIC and Spring RC Servo motor, I tried the available codes on this forum but it did not work.
I want to make the positioning of this servo on the way I like, how can I do it? Can you supply me any codes.
Code: | #include <16f877a.h>
#fuses HS, NOWDT, NOPROTECT // Set Fuses
#use delay(clock = 1000000) // Synchronize with the Oscillator
#define servo PIN_C0
void forward();
void backwards();
void main()
{
while(1)
{
backwards();
delay_ms(5000);
forward();
delay_ms(5000);
}
}
void forward()
{
output_high(servo);
delay_ms(2);
output_low(servo);
delay_ms(18);
}
void backwards()
{
output_high(servo);
delay_ms(.5);
output_low(servo);
delay_ms(19.5);
delay_ms(16);
}
|
|
|
|
septillion
Joined: 21 Jan 2010 Posts: 13
|
|
Posted: Sun Jan 24, 2010 8:54 am |
|
|
delay_ms expects a int16 value, not a float. 0.5 won't work. |
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Sun Jan 24, 2010 11:24 am |
|
|
RC servos are controlled with pulse train. You send a pulse to a servo every 20ms, width of pulse determines where the servo will go and it is typically from 1ms to 2ms in length.
Now said that, you should use search on forum. There is a lot of code posted here.
Go to the forum's search page:
http://www.ccsinfo.com/forum/search.php
Put this in the search box:
RC SERVO
Set it to "Search for all Terms". |
|
|
|