Page 1 of 1

Digital Servo

Posted: Thu Feb 11, 2010 5:10 pm
by Mathy
Hi everybody !

I would like to drive digital servo motor.

Digital servo works better with a 300 Hz refresh rate instead of 50 Hz.

What I have to modify in the pic_servo.c file to increase de refresh rate ?

Thank you so much :)

Mathy

Re: Digital Servo

Posted: Thu Feb 11, 2010 5:42 pm
by Sean
operation at 300Hz will require all the calculated 50Hz values to be divided by 6.

In the Servo c code file, the following substitutions define a 2.5ms channel period. Eight of these make the 20ms cycle time. The values are based on the clock frequency and are used as a H:L pair to form a 16-bit value for one of the timer compare registers:

#define MX_SERVO_PERIODH %a
#define MX_SERVO_PERIODL %b

If you have a fixed clock frequency for this application, it should be possible to replace these substitutions with constant values (or combine the calculated values into an unsigned int, divide by 6, and re-split into H:L bytes).

The following substitution is the multiplier for the calculated position pulse values:

unsigned int MX_SERVO_CLK_COUNT = %j;

Replacing it with the line below should scale the pulses to the new frequency:

unsigned int MX_SERVO_CLK_COUNT = (%j / 6);