Forums

Is PWM capture/measurement without interrupts possible?

Started by Neil Jansen July 27, 2007
Hi,

On my LPC2103 I'm trying to measure the on-time of three PWM signals
from an LM4970 chip. The only way I know to do this is to use a
timer/capture and interrupts; I'm wondering if there's a way to do it
without interrupts. Here's my code with interrupts:

Using Timer0, set up pins as follows:
CAP0.0 - on falling edge, update T0CR0 with current timer/counter value
CAP0.1 - on falling edge, update T0CR1 with current timer/counter value
CAP0.2 - on falling edge, update T0CR2 with current timer/counter value

The last thing to do, is to somehow reset the timer/counter on the
rising edge of the above signals. I can do this with an interrupt,
but I'd rather not unless it's there's no other choice.

I picked the ARM platform over AVR for this project because it looked
like I could do all my pwm input/output in hardware rather than in
code. So is there an easier way to measure pulse width?

Thanks,

Neil

An Engineer's Guide to the LPC2100 Series

Hey Neil:
Why not this approach: run each of the signals into a good sized cap to
ground, (10 MFD) then into separate inputs of the A/D.

on % = Vmeas/Vref

usually this is all you realy need, but if you want time, all you need
to know is the period/freq of the PWM signal to get it.

Would your method be able to work on "100% on time" or "0% on time"
(each case has no transition) This will.

You'll have to farcle around about the size of the cap...smoothing vs
responce.
--- In l..., "jap136542"
wrote:
>
> Hey Neil:
> Why not this approach: run each of the signals into a good sized
cap to
> ground, (10 MFD) then into separate inputs of the A/D.
>
> on % = Vmeas/Vref
>
> usually this is all you realy need, but if you want time, all you
need
> to know is the period/freq of the PWM signal to get it.
>
> Would your method be able to work on "100% on time" or "0% on time"
> (each case has no transition) This will.
>
> You'll have to farcle around about the size of the cap...smoothing
vs
> responce.
>
Just curious...why the aversion to using interrupts? Be aware of the
calibration can of worms you will open with the analog approach...may
or may not be a problem depending on the precision/accuracy you
need. If you're not committed to the LPC you could consider a TI
TMS470 ARM7 (sorry...I know this is an LPC group ;) part in which you
can program the High End Timer module to do your measurement and your
main application can simply read out the duty cycles. But that seems
like it would be a drastic alternative to simply using interrupts on
the LPC part.

Anyway, have a pleasant weekend everyone.
Ryan.
> Just curious...why the aversion to using interrupts? Be aware of the
> calibration can of worms you will open with the analog approach...may
> or may not be a problem depending on the precision/accuracy you
> need. If you're not committed to the LPC you could consider a TI
> TMS470 ARM7 (sorry...I know this is an LPC group ;) part in which you
> can program the High End Timer module to do your measurement and your
> main application can simply read out the duty cycles. But that seems
> like it would be a drastic alternative to simply using interrupts on
> the LPC part.

I had a lot of frustration using interrupts with 8-bit processors...
They are so strung out for some applications, that using them at a
high rate can slow your main code down to a halt... Reading and
outputting multiple pulses at a reasonable frequency while doing other
stuff was almost impossible. I'll probably end up using them, I just
figured I'd ask to see if there was an easier way.