PULSE WIDTH MEASUREMENT USING PIC16F690

Started by andy_angad June 24, 2009
Hey i wanted to measure the width of a square wave pulse..
Neone have a sample code please let me know.

Thank You

> Hey i wanted to measure the width of a square wave pulse..
> Neone have a sample code please let me know.

Dude, this isn't twitter, you can use all of the letters here...
Anyway, I can think of four ways off the top of my head, you didn't
mention what you wanted specifically, so no one can hone in on your task.
For instance, do you want the period, high time or low time?

1) Sit in a tight loop, look for a transition and consult a timer.
2) Set an interrupt that triggers on an edge and consult a timer.
3) Use an ICP (input capture) pin which controls its own timer.
4) Use an interrupt that is triggered at a fixed interval and look at an
I/O line and count hits (your timer triggers the ISR here.)

IMO the best is #3, next best is #2. #2 is especially useful if you
have several lines and you can hook them to Pin Change interrupts. If
you don't have easy access to Pin Change interrupts and need to time
more than one or two signals than #4 works well, but the resolution is
pretty much dictated by how fast you can afford to run the interrupt.
I've used #4 with 10us tic's to time multiple R/C receiver channels in a
remote control. This works really well

As a reference, I don't use #1, I use #2 to handle IR decoding, #3 to
time a SONAR pulse and #4 to look at R/C control signals.

have fun,
DLC

> Thank You
--
Dennis Clark
TTT Enterprises