View Full Version : Time Ellapsed

07-21-2009, 09:20 PM
Hello All!· I would like to keep track of how much time passes after a particular event occurs in my code.· I want the rest·of the·code to continue running in the meantime.· I would like to know·time ellapsed·because I want to execute other code if a time limit is reached.· Can someone help?


Mike Green
07-21-2009, 09:29 PM
Save the value of the system clock (CNT) when your event occurs. When you want to test for elapsed time, just subtract the then current system clock value (CNT) and you'll get an elapsed time in system clock ticks (usually 12.5ns). This works for elapsed times up to around 50 seconds with an 80MHz system clock.

This is the way timeouts are handled in the FullDuplexSerial driver.

07-22-2009, 01:35 AM
Thanks.· CNT is of the type LONG?

07-22-2009, 01:36 AM



NYC Area Prop Club (http://www.gothampropclub.com)

Prop Forum Search (Via Google) (http://search.parallax.com/search?site=parallax&client=parallax&output=xml_no_dtd&proxystylesheet=parallax&proxycustom=<HOME/>&ie=&oe=&lr=)


07-22-2009, 02:50 AM
Another approach is to use one of the cog's counter modules as a timer. The attached demo sets a counter module to free run mode with an update rate of every clock tick. Once you start the counter you simply need to read the phase register for the elapsed time. As with Mike's suggestion, this is good for about 50 seconds; for longer events you'd want to create a timer that runs in its own cog. I included methods in the demo that would allow you to do "splits" like a standard stopwatch.