CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Variable PWM (5-10% duty cycle)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tnay



Joined: 11 Feb 2007
Posts: 4

View user's profile Send private message

Variable PWM (5-10% duty cycle)
PostPosted: Sun Feb 11, 2007 9:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 11, 2007 3:56 pm     Reply with quote

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:
Quote:
PWM compare servo
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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