Pulse width measurement?
Hello,
I want to measure a ~ 3 msec low-high-low pulse that repeats every ~ 30 msec.· Then I need to compare the ratio of 10:1 for calibrating the device.·
I'd like·to do an event-count of the resonator clock cycles (or some other·oscillator that I could provide if the microcontroller likes this better
).· I would count 1] while the pulse is high, and 2] count from the first high pulse until the next high pulse, then compare the two counts.··
Can the SX family handle that?· Is there a better parallax product for this project?·
Thanks very much for your help.
Jim Barnes
I want to measure a ~ 3 msec low-high-low pulse that repeats every ~ 30 msec.· Then I need to compare the ratio of 10:1 for calibrating the device.·
I'd like·to do an event-count of the resonator clock cycles (or some other·oscillator that I could provide if the microcontroller likes this better
![cool.gif](http://forums.parallax.com/images/smilies/cool.gif)
Can the SX family handle that?· Is there a better parallax product for this project?·
Thanks very much for your help.
Jim Barnes
Comments
Sorry if this is a redundant post--I searched on pulse width and on counter and didn't see anything that looked like this.· Will look further....any hints on search keywords appreciated.......·tail between legs.....
Jim
Thanks, been reading posts and documentation. ·I need resolution of 1 microsec or better.· Again, measuring two time intervals simultaenously, starting from the same high edge:· ·t1 (~3msec) is the interval until the the high pulse goes back low......t2 (~30 msec) is·the·interval until the·next high edge on the same·pin.·· Ideally the same high edge·initiates both measurements.·· I only need to·compare the ratio of the·two times,·make an adjustment in the hardware, and repeat until the ratio is correct.· Time measurement is critical, the rest can take "forever."·
In the example Measure_Pulses.SXB, I think what is going on is the ISR starts every 10 microsec and increments a count if the given bit is high, then over and over again.· Please, have I got it right?· If so, I need to keep the ISR shorter than the resolution I want to achieve, right?· ·How do I figure that practical limit?· Don't be afraid to dumb it down for me.·
Clearly I need a book and a quiet place as well as your help.· Is Gunther's book a good place to start?· Should I be looking at the·SX-28 or the -48?· SX/B or ASM?·Any recommendation/help is grealy appreciated.
Jim
Just foir fun I wanted to see how tight one could create some assembler code to do what I think you are looking to accomplish. The code must use ra.1 as the high/low input, and will count the duration (2 bytes) that a continuous high or low is detected. When that input pin transitions to the opposite state (say low), the accumulated count is output on ports e/d, and the counter is zroed. The accumulation starts again, and when the input again transitions (now high), the accumulated count is put on ports c/b. This way you can separately see the high and low results in real time via leds connected to those 32 port pins.
Although fairly short, the program is quite intricate -even tricky in spots- and ANY alteration will cause it to fail unless certain timing/code length principles are upheld. As it stands, it will (just) work up to minimum durations of 440 nano seconds, and that's its resolution.
Sixteen bit accumulators permit 65355 counts to be captured, so at the programmed speed of 440 nanoseconds, permits a slowest duration of .44 x 65535 = 28.8 milliseconds... perhaps just outside your range. If that is the case, one could safely slow the interrupt period down from minus 22 cycles to minus 25 cycles (as in the commented out "INTVAL·EQU -25·" line, and that would yield a 500 nano second resolution. Then the slowest you could capture (that is per high OR per low duration) would be .5 x 65535 = 32.7 milliseconds.
Have fun with this.
Cheers,
Peter (pjv)