SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By cain8885
#22775
Can someone please verify my calculations for driving my continuous rotation servo motor via my pwm channel. I am having some odd behaviour.

I am running a pic 18f4520 and am running it 8mhz using the internal osc.
Everything runs fine and i can get the motor to turn in one direction. My PWM is setup as follows.

OpenPWM1(0xfb);
OpenTimer2(T2_PS_1_16 & T2_POST_1_1 & TIMER_INT_OFF);
SetDCPWM1(75);

So my PR2 is 251
my DC is at 75
and my timer2 prescaler is set to 16.

I am trying to generate a 1.5ms pulse at ~20ms intervals. I ran through the calculations an this appears to be correct. THe motor does indeed run and i can change the speed of the motor by adjusting the DC. However, i am unsure of how to get the motor to turn the other direction. It seems no matter how i adjust the DC it still goes in the same direction. Perhaps i need to adjust the set screw on the servo?

Additionally i have a servo motor that is not continuous rotation that i have setup as above. To test the motor, i have a loop setup that will move the motor through different positions in a loop.

Pseudo code is
OpenPWM1(0xfb);
OpenTimer2(T2_PS_1_16 & T2_POST_1_1 & TIMER_INT_OFF);
SetDCPWM1(55);
while(1)
{
delay();
SetDCPWM1(65);
delay();
SetDCPWM1(75);
delay();
SetDCPWM1(85);
delay();
SetDCPWM1(95);
delay();
SetDCPWM1(85);
delay();
SetDCPWM1(75);
delay();
SetDCPWM1(65);
delay();
SetDCPWM1(55);
}

When i intialize the motor originally it goes to a position and then begins to rotate through the positions i have listed. I am running this in the debug mode of the icd2. However after a few positions, i dont actually know which one, the program will die and go into pause mode. I am not sure why this is happening. THe only guess i have is that by jerking the motor around so frequently that i am drawing too much power? I have the motors power connected to the same powersource as the pic. As well the power source, a 9vdc 600ma wall wart is powering two pics, and some leds in addition to my motor. I have capacitors running between power and ground. Does this sound like a reasonable explanation for why my program would go into pause?

THanks
Brian
By jandirks
#22822
A servo can draw 1A easily... It could be that you need to power your servo with another source.
By Philba
#22865
that's a very good point. I saw that exact situation with a robot I built using modified servos. A separate supply for the logic would work or
you can solve the problem by using a large capacitor to ground at the input of your logic's voltage regulator and putting a rectifier in series before the cap. the cap will supply current when the battery droops from the servo's draw. The diode prevents the servos from drawing down the cap. Best would be a Schottky rectifier but a silicon rectifier would be ok if you can afford the .7V voltage drop. Probably best to use a 1A device.