Microchip | The Embedded Control Solutions Company Register Login
Browse All
Tropfen kft.
 5 Code Snippets

RC Servo motor driver

Tropfen kft.

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.

Usage
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

Configuration
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.

Categories

Release History

  • Oct 18, 2011

    Version: 1.0.0

    Initial release

Download Contact the Developer

*Required Fields


  • Current Version:1.0.0
  • Created:Oct 19, 2011
  • Updated:Feb 26, 2015
  • Downloads:8902
  • MPLAB Version:8.76
  • C Compiler:C30 3.25
  • Development Tools:ICD2
  • Supported Devices:dcPIC30F4013, dsPIC33FJ64MC204 and similar PICs.

Corporate News

Resources

Stay Connected

Stay up to date with the latest news from Microchip Technology.