Weird SX use, need help
MacGeek117
Posts: 747
I'm thinking of using an SX to measure time, in mS, between 2 events. How would I do this? I have looked through the help file, but can't find any info. BTW, the FREQ is 4MHz.
RoboGeek
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
There are·3 kinds of people in the world,
the dreamers, the do-ers, and the "Oh, what's this button do"-ers.
Formerly bugg.
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.startrek.com
·
RoboGeek
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
There are·3 kinds of people in the world,
the dreamers, the do-ers, and the "Oh, what's this button do"-ers.
Formerly bugg.
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.startrek.com
·
Comments
You could have your start and stop events trigger two input pins, each set up to interrupt the SX on transition. Also configure the SX to interrupt on RTCC rollover.
Set up several bytes to be the count variable, and keep a state variable byte.
In the ISR, the ISR would need to figure out why it was interrupted, and do the right thing: on the start event, zero the count variables and set the state to "counting". On the stop event, set the state to "stopped". On RTCC rollover, if the state is "counting", increment the count variables.
Ordinarily, you'd need to take extra care when combining RTCC rollover and external event interrupt triggers because an external event interrupt can hide a rollover interrupt. But in this case, as soon as you get the external interrupt, you'll either zero the counts or stop the counting, so masking a rollover interrupt won't matter.
The main program loops, waiting for the state to become "stopped", at which point it will translate the count number to milliseconds, display it, then set the state to "waiting".
There are lots of details to work out - how often to have the RTCC rollover and increment the counts, how many count bytes you'd need, how counts translate to milliseconds, how to display the results, how to design and condition the event trigger signals, etc. But something like this would probably work.
David
If you don't have the book, the code is available on line, but it is in Assembly language - not SX/B.
I don't think this is at all a problem because the SX is made to be deterministic. The biggest question is if you care about accuracy beyond one-millionth of the crystal's rate. To do so requires you provide a more specialized oscillator source.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
·