Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [lpc2000] Re: PWM width detection

2006-02-18 by Onestone

The 'standard' way to do this is to use 1 pin. ISR latency on slow small 
micros is usually more than fast enough. On an LPC it should be a shoe 
in. 1 instruction cycle to flip the bit sense. How hard can it be. A 
typical ISR to measure pulse width on most micros requires fewer than 10 
instructions. Your final sentence may be true, but this is the case in 
99% of applications, and is certainly true in your case, even with the 
comparatively poor interrupt latency of the LPC2xxx. On the odd 
occasions where the pulses are too fast I would suggest that using two 
pins is a poor solution anyway, since the resolution of meaurement will 
only be typically 2-4 bits at most, and other solutions would offer a 
better result.

Cheers

Al

Ryan Niemi wrote:

>I recently implemented pulse width measurement on an LPC2124 to detect
>the width of pulses from an R/C radio receiver (varies between 1ms and
>2ms positive-going pulse width) for a theatrical motion control and
>lighting control project.  There's an interesting shortcoming that I
>encountered, each capture pin can only capture a rising or falling
>edge, but not both.  So to measure pulse width, I found it necessary
>to use *two* capture pins tied together, one to capture the rising
>edge and another to capture the falling edge.  The main loop of the
>program compares the two, and if the count on the falling edge capture
>is larger than the count on the rising edge capture, then pulse_width
>= falling_edge_capture - rising_edge_capture.
>
>The Hitex book includes an example whose description says it measures
>a pulse width, but the example shown (using one capture pin) very
>clearly does not measure pulse width and is incomplete, and merely
>measures the time between pulses (but not the pulse width).  Now my
>curiosity is had, has anyone succeeded in measuring pulse widths
>without using multiple capture pins?  From the way the LPC capture
>units are set up, I doubt it's possible, short of flipping the capture
>edge polarity in an ISR.  ISR-based solutions are only really useful
>if the pulse width is larger than the execution time of the ISR + any
>interrupt latency due to other ISR's executing at the time.
>
>-Ryan
>
>
>--- In lpc2000@yahoogroups.com, "Joel Winarske" <joelw@...> wrote:
>  
>
>>Hi J,
>>
>>    
>>
>>>Does anyone have any code examples of how I can use a LPC2138 to
>>>      
>>>
>detect
>  
>
>>>the width of the positive pulse in a PWM signal. I know I can use the
>>>timer circuit and detect the rising and falling edges do some math and
>>>determine the width. I am very new to micro controllers and some code
>>>examples or guidance would be greatly appreciated.
>>>      
>>>
>>For some theory take a look at this Atmel application note:
>>AVR135: Using Timer Capture to Measure PWM Duty Cycle   (12 pages,
>>    
>>
>revision
>  
>
>>A, updated 10/05)
>>Found here:
>>    
>>
>http://www.atmel.com/dyn/products/app_notes.asp?family_id=607
>  
>
>>As for the LPC2100 you would use the Capture feature of the Timer
>>peripheral.  Setup timer to generate an interrupt on capture pin
>>    
>>
>leading or
>  
>
>>trailing edge.  In the interrupt routine read the capture register
>>    
>>
>value and
>  
>
>>pass it on to your algorithm.  
>>
>>Be sure to read the correct section of the errata sheet related to
>>    
>>
>TIMER.
>  
>
>> 
>>
>>Joel
>>    
>>
>
>
>
>
>
>
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>
>
>  
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.