I'm trying to capture the width of a pulse using the capture
timers on the LPC2106 and getting an accurate reading every
time has proven difficult. The pulses are 200 to 700
microseconds long. I thought that I could capture them in
the following way:
Algorithm 1:
o set up capture timer channel 0 to interrupt on each edge
o on interrupt check level to see if high to indicate a
rising edge
o if high, remember captured time and wait for falling edge
o when falling edge occurs subtract rising edge time and
queue up the length of the pulse
I implemented this algorithm and my numbers vary quite a bit.
If I scope the signals, they are clean so the variance is not
due to noise and is due to interrupt collision or a misunderstanding
of the timer capture. The above algorithm will fail if another
interrupt occurs preventing the captured count from being read
before another edge transition occurs. This is probably what is
happening in my case. So I've been thinking about how else to
capture the two edges without software getting in the way. The
only way I can think of is to use two capture inputs and a match
register.
Algorthm 2:
o the first capture input captures the time on the rising edge
o the second capture input captures the time on the falling edge
o the match register provides a timed interrupt in which at
least two edges have been captured
In my case I'd set it to be a millisecond since the pulse is
periodic with about a millisecond period (I'm really measuring the
duty cycle). Then comparing the rising and falling edge capture
times, I can deduce whether I've captured the low pulse (falling
edge before rising edge) or the high pulse (rising edge before
falling edge) and calculate the high pulse from the captured times.
Also by taking a group of measurements, I should get some of
the high pulse and some of the low pulse. Using this info, I
should be able to deduce the period as well instead of measuring
that independantly.
While this algorithm seems like it should work, it uses two inputs
per pulse input. If someone else has a better idea please toss
it into the arena.
RobMessage
accurate pulse measurements
2005-01-21 by chazeltopman
Attachments
- No local attachments were found for this message.