I just wanted to know how you are programming your PIC to drive more than one servo motor.
I do something like this:
As you know a pulse sent to the servo motor is max 2ms so I can drive 10 servo's (2ms * 10 = 20ms)
Code: Select all
short number_of_servo = 8; // max 10
short T = 20000; // 20 ms
short T_on[number_of_servo], T_off = 0, i = 0, PortB = 1;
// initialise T_on
for (i = 0; i < number_of_servo; ++i)
T_on[i] = 1000; // 1 ms
for (i = 0; i < <number_of_servo; ++i)
short j = 0;
portb = 0; // pseudocode: all output pins of portb set to 0
portb = PortB; // pseudocode: uses portb as output with PortB pin high
//The problem of the delay_us function is that it only allows a char variable as
//argument so I came up with this 3 lines of code to "bypass" this little problem.
for (j = 0; j < T_on[i] / 255; ++j)
delay_us(T_on[i] - (T_on[i] * 255) / 255);
PortB = PortB * 2; // or PortB << 1, a little shift register to change the output pin
T_off = T_off + T_on[i];
portb = 0; //pseudocode: all output pins of portb set to 0.
PortB = 1; //put the output pin back to the initial pin
T_off = T - T_off;
for (i = 0; i < T_off / 255; ++i)
delay_us(T_off - (T_off / 255) * 255);
I think that's it.