Two intervals from one pulse train
Jim Barnes
Posts: 9
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
·
Comments
You can implement wait...() function with wait... instructions in SPIN or PASM. If they need have the same execution / delay times (do they?) you won't introduce any error by using this software instead of hardware.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Airspace V - international hangar flying!
www.airspace-v.com/ggadgets for tools & toys
I'm trying to figure this language out and not be totally helpless.· The way I understand what you wrote is that I use the waitpeq() as follows for a pulse on, say, ·pin3:
waitpeq(%0000,· %1000, 0)······ '· wait for low on pin3 before starting--the mask is always %1000 to isolate pin3
waitpeq(%1000, %1000, 0)······· '· wait until first high transition of pin3
toHigh1st := cnt······················· ' initial count
waitpeq(%0000, %1000,0)········ ' wait for pulse to come back to low
toLow := cnt····························· ' count acquired as of end of pulse
waitpeq(%1000, %1000,0)········ ' wait for next high transition
tohigh2nd := cnt······················· ' count acquired as of next high
'· now post processing
highDuration := toLow - toHigh1st
periodDuration := toHigh2nd - toHigh1st
ratio := highDuration / periodDuration
Thanks for your time and please point out any errors in my way of thinking!!
Jim
I have it not tested, this is your turn...
Andy
Edit: Sorry, missed your last post, looks very similar [noparse]:)[/noparse]
Post Edited (Ariba) : 3/19/2009 5:01:03 PM GMT