Shop OBEX P1 Docs P2 Docs Learn Events
Time Ellapsed — Parallax Forums

Time Ellapsed

jsestijsesti Posts: 5
edited 2009-07-21 19:50 in Propeller 1
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?

THANKS·smilewinkgrin.gif

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-21 14:29
    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.
  • jsestijsesti Posts: 5
    edited 2009-07-21 18:35
    Thanks.· CNT is of the type LONG?
  • CassLanCassLan Posts: 586
    edited 2009-07-21 18:36
    Yep

    Rick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    NYC Area Prop Club

    Prop Forum Search (Via Google)

    ·
  • JonnyMacJonnyMac Posts: 9,197
    edited 2009-07-21 19:50
    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.
Sign In or Register to comment.