An object to create 'NowSec'
Erlend
Posts: 612
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
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.
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.