RC Servo motor driver
RC Servo motor driver up to 6 servos. It uses a dsPIC30f4013 and two timers. TMR3 is used as a custom timer, while an other timer must be configured for 1ms interrupt intervals. I have used this driver module to move a webcam mounted on two RC servos
About this Code Example
This is a driver for RC Servo motors. Up to 6 can be configured. Each one can have a different minimum and maximum pulse width. Position can be set in percentage.
Driver loops trough each servo one after another and generates the driving signal for it. At the end it will wait until 18ms have been elapsed from the beginning of the whole loop.In this way each RC servo is updated every 18ms.
1. Edit c_rcservo.c and c_rcservo.h file to configure your ports where RC Servos are. You can set also minimum and maximum pulse width to fit your RC servo.
2. Register isr_rcservo_tmr in TMR3 interrupt, and isr_rcservo_1ms in 1 ms cycle time interrupt from i_rcservo.h
3. Call init_rcservo from w_rcservo.h.
4. Call setServoPosition to set a given servos position in percentage from rcservo.h
c_rcservo.c and c_rcservo.h are the files where configuration is stored.
In c_rcservo.c an array is used where Port, TRIS, bit number, pulse width min and pulse widht max can be configured. Do not forget to update in the header file the SERVO_CNT to matchthe item number of the array.
In c_rcservo.h you have to configure how much TMRcnt is 1 us. For 60MHz Fosc is shall be 30 on a dsPIC33F.
Open collector output can be emulated by leaving the USE_OC_OUTPUTS defined.
- Oct 18, 2011