View previous topic :: View next topic |
Author |
Message |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
Pulse Width Measuring w/ One CCP Pin |
Posted: Sat Sep 15, 2007 9:27 pm |
|
|
3.249
18LF6627 3.3V
Hello All,
Once again I've added functionality in hardware prior to understanding the requirements of the PIC. I was hoping to measure the duty cycle of 64uS period PWM signal (it's an RSSI reading). It appears that the 'desired' way is to use to CCPs to catch the rising and falling edge. I've only got one and I'd like to find a 'non-blocking' solution for measuring the pulse width.
My searching has shown me the ex_pulse.c solution (blocking). And other similar approaches.
Is there some way to change the CCP's detection from high_to_low to low_to_high midstream?
Or is there some other way to skin the cat?
Thanks,
John |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 16, 2007 12:01 am |
|
|
http://www.ccsinfo.com/forum/viewtopic.php?t=31470
However, these methods use interrupts, and that takes a
certain amount of time as overhead. Make sure the PIC
is running faster than 4 MHz (20 MHz would be much better).
You didn't say how short the pulse can be. If it's too short,
you're not going to be able to measure it, given the overhead
requirement to get in and out of an interrupt service routine. |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Sun Sep 16, 2007 12:35 am |
|
|
PCM,
Thanks. I didn't see that thread when I was searching. I will look at those examples in the morning.
Pulse width will be 0 or 15-62uS. So that should be enough time for the ISR?
Forgot to post processor speed: 40MHz.
John |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 16, 2007 12:55 am |
|
|
At 40 MHz with just the CCP1 interrupt running, the interrupt overhead
is about 4 us, not including the code in the isr. Lets say the isr code is
brief, and takes only 10 instruction cycles. That would give about 5 us
per interrupt. That's fast enough to work with a 15 us pulse, where an
interrupt occurs on each edge of the pulse. |
|
|
|