Joined: 30 Oct 2003 Posts: 209 Location: Norfolk, England
Determining PWM duty cycle with one pin
Posted: Tue Aug 03, 2010 5:14 am
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
Posted: Tue Aug 03, 2010 12:19 pm
Here are examples of various ways to measure a pulse.
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
Measuring PWM
Posted: Thu Aug 05, 2010 3:41 pm
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.
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