Instead of controlling it straight put a transistor on the pic pin and connect the servo to it and 5v also so you toggle the transistor which in turn controls the servo. I think you would need a mosfet. But heh im not 100% sure not even 20% sure but at least its a thought.
Umm... Jason. Have you ever controlled a servo with a microcontroller? Very weird advice!
Maybe I just don't get what you're talking about.
Anyway, ColinTheProgrammer, here's a diagram to wire a typical servo:
**broken link removed**
Now the notes to go with the above image:
1. The wire colors are not necessarily correct if your servo is not a Futaba, but those colors are very common. If you're unsure, Google for the proper colors for your brand/model of servo. There will be a power, a ground and a control wire.
2. The servo power should usually come from a different source than the one that supplies your MCU, and should be between 4.8V and 6V. 4.8V is the voltage of a stock battery pack when you buy a radio to fly your airplane/car/boat (or whatever). Servos can handle a bit more juice, but if you go much past 6V you risk cooking the servo.
If your MCU power supply can supply enough power without sagging and resetting the MCU when the servo moves, then you can use that. Either way the grounds MUST be common, as shown in the diagram.
3. The control line can be connected directly to the MCU pin. It's a logic line, and is made for that. Don't worry about the voltage. Your PIC puts out 5V on a pin when it's set high, provided the PIC is being supplied with 5V (it almost certainly is). The servo should receive a high pulse approximately every 20mS. That pulse should be approximately 1.5mS for center, 1mS for full counter-clockwise (CCW) and 2mS for full CW rotation, and of course varying durations between those for the full range of motion. Your servo may vary a bit, so test it.
For example: Say you want to drive the servo fully CW. Your program should send a 2mS high pulse and then 18mS of low, over and over, constantly to hold the servo in that position. This is called a pulse-train. To drive it to center and hold it there the MCU should constantly send a 1.5mS high pulse and then 18.5mS of low.
Listen closely when it's rotated fully in each direction. If it's buzzing it may be stalled against the end stops. This eats a lot of power and is hard on the servo, so adjust your pulse duty cycle until it stops.
If you can understand C, here's an ultra-simple demo program in BoostC for 18F448 that shows how it's done for two servos, on RB0 and RC3. This is
NOT how you would normally control a servo. It's only a demo. It uses delays to do the pulses. Normally you'd use timers and interrupts so you can get something else done while driving the pulse-train controlling the servo in the background.
Code:
#include <system.h>
#pragma CLOCK_FREQ 20000000
#pragma DATA _CONFIG1H, _HS_OSC_1H
#pragma DATA _CONFIG2H, _WDT_OFF_2H
#pragma DATA _CONFIG4L, _LVP_OFF_4L
void main(void)
{
int i;
trisb=trisc=0;
while(1){
for(i=0;i<50;i++){ //50 pulses 1.5mS - center
latb.0=1;
latc.3=1;
delay_ms(1);
delay_us(200);
latb.0=0;
latc.3=0;
delay_ms(18);
delay_100us(5);
}
delay_ms(100);
for(i=0;i<50;i++){ //50 pulses 1mS - cw
latb.0=1;
latc.3=1;
delay_100us(3);
delay_us(80);
latb.0=0;
latc.3=0;
delay_ms(18);
delay_100us(7);
}
delay_ms(100);
for(i=0;i<50;i++){ //50 pulses 1.5mS - center
latb.0=1;
latc.3=1;
delay_ms(1);
delay_us(200);
latb.0=0;
latc.3=0;
delay_ms(18);
delay_100us(5);
}
delay_ms(100);
for(i=0;i<50;i++){ //50 pulses 2mS - ccw
latb.0=1;
latc.3=1;
delay_ms(2);
latb.0=0;
latc.3=0;
delay_ms(18);
}
delay_ms(100);
}
}