Jim Barnes
03-19-2009, 04:30 AM
Hi Gang,
Need to measure two time intervals from one signal.··First is the time high of a ~ 1-5 ms positive going pulse.· Secons is the period, or time·from the same initial high edge to the next high edge.· Ideally this is a 10:1 ratio, and ultimately the ratio is what I'm after, so a duty cycle measurement might suffice (?)
My pseudo-code:
VAR long ratio, long t1, long t2, long counter
·t1 = t2 = ratio = 0
wait for high edge
····· start counter··································· OR······· start ctrA, ctrB ·on highedge
····· wait for low edge·········································
············ t1 = counter·· 'short time······················ Stop ctrA on low edge,·· t1 = ctrA
····· wait for next high edge·································Stop ctrB on·high edge,·· t2 = ctrB
·············t2 = counter·· 'long time
······ratio = t2/t1
OR·
Start ctrA
The waitpeq looks promising but I thought the built in counter functions may be a better choice but alas, I am slightly confused with their structure.··I need counter resolution of at least 1 us· or better, and preferably the two times are measured from the same starting edge.·
Any help is appreciated.· Thanks,
Jim
·
Need to measure two time intervals from one signal.··First is the time high of a ~ 1-5 ms positive going pulse.· Secons is the period, or time·from the same initial high edge to the next high edge.· Ideally this is a 10:1 ratio, and ultimately the ratio is what I'm after, so a duty cycle measurement might suffice (?)
My pseudo-code:
VAR long ratio, long t1, long t2, long counter
·t1 = t2 = ratio = 0
wait for high edge
····· start counter··································· OR······· start ctrA, ctrB ·on highedge
····· wait for low edge·········································
············ t1 = counter·· 'short time······················ Stop ctrA on low edge,·· t1 = ctrA
····· wait for next high edge·································Stop ctrB on·high edge,·· t2 = ctrB
·············t2 = counter·· 'long time
······ratio = t2/t1
OR·
Start ctrA
The waitpeq looks promising but I thought the built in counter functions may be a better choice but alas, I am slightly confused with their structure.··I need counter resolution of at least 1 us· or better, and preferably the two times are measured from the same starting edge.·
Any help is appreciated.· Thanks,
Jim
·