Author Options:

why my servo works on arduino and not pic microcontroller? Answered


Iam trying to use servo to control the turning angel of RC car , my servo is feetech fs5113m .

1st i tried arduino , using a 5 volt supply voltage "1A" for the servo , which is lower than its actual required voltage , but it was still working perfect, i used the "sweep" in arduino examples just to test it.

then i used my pic16f877a to run it , and i was facing a problem where the servo keep 'buzzing' and doesn't work until i give it a push , and i was using the same power supply , then i tried both 7 and 6 volts "0.8A". and nothing but "buzzing"

here's the code :

void servoRotate0() //0 Degree
{ unsigned int i; for(i=0;i<50;i++) { PORTB.F0 = 1; Delay_us(800); PORTB.F0 = 0; Delay_us(19200); } }

void servoRotate90() //90 Degree { unsigned int i; for(i=0;i<50;i++) { PORTB.F0 = 1; Delay_us(1500); PORTB.F0 = 0; Delay_us(18500); } }

void servoRotate180() //180 Degree { unsigned int i; for(i=0;i<50;i++) { PORTB.F0 = 1; Delay_us(2200); PORTB.F0 = 0; Delay_us(17800); } }

void main() { TRISB = 0; // PORTB as Ouput Port do { servoRotate0(); //0 Degree Delay_ms(1000); servoRotate90(); //90 Degree Delay_ms(1000); servoRotate180(); //180 Degree delay_ms(1000); }while(1); }

and its running on ISIS simulation , and its a code that i actually took from someone who tried it and worked ,

so help me with this please.



5 years ago

The servo needs a pulse width modulated signal at a very specific width, it also needs this repeated at a frame rate of around every 20 msec.

omar emad
omar emad

Answer 5 years ago

well its already repeated at fram rate around 20msec , and the pulse rate should be from 0.7 ms to 2.3 ms that for all the servos that i have used before .

iam trying to find any article about such problem , and i just can't .

arduino "sweep" example has the same pulse rate and repeate rate ,, and works on all servos , so i guess this shouldn't be the problem ..


Answer 5 years ago

How are you coding the pic16f877a which will run much faster than the arduino thus you would have to change the delays in the code.


may help you.

"Servos, as commonly found in radio control toys, are a very accurate motor/gearbox assembly that can be repeatedly moved to the same position due to their internal position sensor. Generally servos require a pulse of 0.75 to 2.25ms every 20ms, and this pulse must be constantly repeated every 20ms.

Once the pulse is lost the servo will lose its position. The servo command starts a pin pulsing high for length of time pulse (x0.01 ms) every 20ms.

Servo commands adjust the pulse length to the new pulse value, hence moving the servo."