An object to create 'NowSec'

in Propeller 1
I am sure this problem has been solved before. I have searched around but I cannot find it:
What I need is a counter of seconds since boot time. Thanks to some tidying up of my code, I now have a cog to spare. I assume a dedicated cog is required - or a dedicated chip.
Any idea for an Object - or a chip - is much appreciated.
Erlend
What I need is a counter of seconds since boot time. Thanks to some tidying up of my code, I now have a cog to spare. I assume a dedicated cog is required - or a dedicated chip.
Any idea for an Object - or a chip - is much appreciated.
Erlend
Comments
'' WARNING: this is untested code, it's just a proof of concept '' VAR long seconds_since_boot long stack[8] ' probably bigger than needed '' function to increment seconds_since_boot once per second PRI timer | next, freq freq := _CLKFREQ next := CNT repeat waitcnt(next += freq) seconds_since_boot++ '' call starttimer to start the timer PUB starttimer cognew(timer, @stack) ' run the timer function in a new COG '' call gettimer to get the integer count of seconds since boot PUB gettimer return seconds_since_boot
rayslogic.com/propeller/Programming/RTC/PropTime.zip
Posted about it here a long time ago: https://forums.parallax.com/discussion/106263/proptime-unix-style-rtc-using-one-cog/p1
I've attached a little demo that shows how I use my background process. If you don't have a spare cog, my time object (jm_time_80.spin) will keep running count of milliseconds as well -- the difference is that you MUST access one of the methods that call the mark() method in that object before the cnt register runs a full, 32-bit cycle (about 53 seconds at 80MHz). Use of this is easy, just call time.seconds when you want to know the elapsed seconds. I'm doing this in the demo as well.
I created jm_time_80.spin because I was coding a laser-tag controller and needed a bunch of timers, but had no available cogs (hence no background process). Thankfully, it all worked out well. If you don't need to do anything else as a background process, it's a good way to go (as others have shown with similar code).
It can be this easy to change the state of the LED based on the time since boot.
obj runtime : "jm_time_80" pub main runtime.start dira[LED] := 1 repeat outa[LED] := runtime.seconds & 1
Thanks a lot!
If someone had the time to go through all the posts and collect the code and ideas posted by the forumistas over the years it would probably cover 99% of the code needed for any project.