|
|
View previous topic :: View next topic |
Author |
Message |
tnay
Joined: 11 Feb 2007 Posts: 4
|
Variable PWM (5-10% duty cycle) |
Posted: Sun Feb 11, 2007 9:20 am |
|
|
Hi,
I try to look everywhere, but I can't seem to find any satisfactory answer, so I hope someone can help me. I have a project on a 3-DOF robotic arm and i need to generate a PWM for typical hobby servo motor. This servo operates at 50Hz PWM with duty cycle of 5-10%.
1) If I use the build-in PWM, the 10-bits resolution will spread evenly over the 0-100% right? If that is the case, then the 5% different is equivalent to 5% of the 10-bits, which is only 51 steps? I hope I am wrong, because I need a 10-bits resolution over the 5%.
2) I need to generate PWM with variable duty cycle (from 5-10%), following some complex trigonometry function, I read that I can achieve this with the math library. For a simpler example, duty time = sin (c/t), where c is a constant, and t is a variable from an input. My point is that I want the PWM duty cycle to change at EVERY pulse. If it was a simple linear function, it would be easy. But my function is far more complex than that, I believe it would consume a lot of time and resource, won't it?
Therefore I think maybe I can use the delay function, where it look up the value from an array or table which is pre-calculated.
I have very limited knowledge on PIC and I just get started. I have the tendency to apply what I have learn into my work immediately even when I haven't learn enough. Pardon me if this is a silly question. I appreciate it if someone has a better alternative. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 11, 2007 3:56 pm |
|
|
This post contains the formula for calculating the PWM frequency:
http://www.ccsinfo.com/forum/viewtopic.php?t=17993
The lowest PWM frequency that you can get with a practical crystal freq
such as 4 MHz, is 244 Hz.
For other options, look at the CCS driver file, Servos.c, which is
in this folder:
c:\program files\picc\drivers\servos.c
Read various articles on other methods. For example, to read articles
on the Microchip forum about using the Compare module to generate
servo pulses, put this search string into Google:
Quote: | PWM servo compare site:forum.microchip.com |
Some of those articles will help explain the Servo control options.
Actually, there are a lot of good articles, if you don't restrict the
Google search to the Microchip site. Try this one too:
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|