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

Determining PWM duty cycle with one pin

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



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

Determining PWM duty cycle with one pin
PostPosted: Tue Aug 03, 2010 5:14 am     Reply with quote

Hi, I am thinking about how to determine the duty cycle of a incoming 5kHz TTL signal.
I have the signal connected to a CCP pin. Obviously no problem in determining the frequency. Well I say that but I am resetting timer1 in the interrupt, you can't assume that the interrupt will occur at a fixed time after the capture...there must be a way around that?

A solution for duty may be to switch from RE to FE detection after the interrupt but it doesn't seem very neat, and so math will be required in the interrupt routine slowing it down (although probably not an issue in this case).

Any good ideas. This must be a common(ish) application for the CCP module?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 03, 2010 12:19 pm     Reply with quote

Here are examples of various ways to measure a pulse.

Using CCP:
Quote:

c:\program files\picc\examples\ex_ccpmp.c

Using a Timer:
Quote:

c:\program files\picc\examples\ex_pulse.c

Using software counting loops:
http://www.ccsinfo.com/forum/viewtopic.php?t=42353
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

Measuring PWM
PostPosted: Thu Aug 05, 2010 3:41 pm     Reply with quote

Two possible methods

1) Make the amplitude of the input signal the same as your PIC power rails, process with a low pass filter, and apply to one of the analogue input pins. The ADC measures the duty ratio directly.

2) Sample the input signal at random intervals. Over a period of time the ratio (Total Number of 1's / Total Number of samples) is your duty ratio. The trick here is to make sure that you do NOT synchronise your sampling to the input signal. Increasing the number of samples gives a more accurate result.

Mike Walne
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