Author Topic: PWM control  (Read 2900 times)

0 Members and 1 Guest are viewing this topic.

Offline daisordanTopic starter

  • Jr. Member
  • **
  • Posts: 15
  • Helpful? 0
PWM control
« on: February 23, 2011, 09:27:02 AM »
thx
« Last Edit: March 17, 2011, 06:48:45 AM by daisordan »

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: PWM control
« Reply #1 on: February 23, 2011, 10:10:02 AM »
Quote
C Compiler
Which C Compiler?

Quote
PWM1 for moving left or right and PWM2 for forward or backward.
What Servo controller or how are the Servos connected to get this functionality?

What do the 'canned' timer and PWM function really do?
Are they using the PIC's CCP module or TMR2 or software timing?
Have you used a code simulator to look at what these function truely do?

Quote
PWM signal will send to a servo and move
I assume that it should be outputting a 1 to 2msec high pulse every 20msec.
Have you verified this is so with and O'scope?

You OpenPWM1 then SetOutputPWM1 but do not SetOutputPWM2 after OpenPWM2!!!!


Offline daisordanTopic starter

  • Jr. Member
  • **
  • Posts: 15
  • Helpful? 0
Re: PWM control
« Reply #2 on: February 26, 2011, 02:29:47 PM »
thanks for the reply :)
1) im using C18 C Compiler Libraries.
2) The PIC will send the pulse to the servos with CCP1 and CCP2 like if the PIC send 1.3ms to the servos it will move straight. If i run the code 1 by 1 it can move backward or forward. But now after i put them together, It stops after moving forward.
3) I have try to put SetOutputPWM2 after that, but it comes out error. It say call of function without prototype.

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: PWM control
« Reply #3 on: February 26, 2011, 04:36:58 PM »
The PIC's CCP/PWM module is not good to use for RC servo control. The first problem is in the period to duty cycle relation, 5 to 10% duty. The CCP/PWM module can do this but the duty cycle resolution is very poor. The second is the period of 20msec which is a 50Hz frequency. Look at the data sheet, there is a table of PWM frequencies for a reasonable PIC clcok. The slowest for a 20MHz clock is about 1.2kHz. Some peple have gotten the PWM module to output a slower frequency by lowering the PIC clock but now the PIC can not do much else since it is running so slow.
This is the same problem of using software timing to generate the Servo pulses.

A better way is to use two hardware timers, one for the period on 20msec and a second for timing the pulse duration and Interrupts to start and stop the servo pulses. Search the web for "PIC servo controller" to find projects that use this method.

Hint: Both (or all) servos do not need to the a pulse at the same time. You can pulse one servo (PIC output pin) then when that is finished pulse the next servo. This way you only need one timer for the pulse duration that get re-set up for each servo.
« Last Edit: February 26, 2011, 05:03:49 PM by waltr »

 


data_list