keeping time but not waiting
Digital Junkie
Posts: 11
Hello,
I just got my propeller and I was wondering if there is a way to keep time but not waiting for it to pass. I want to send data to the computer every 2-60 seconds (I want to be able to change this value from 2secs to 60secs) but want to continue running many other things in the code. Is this possible using the cnt someway.
I just got my propeller and I was wondering if there is a way to keep time but not waiting for it to pass. I want to send data to the computer every 2-60 seconds (I want to be able to change this value from 2secs to 60secs) but want to continue running many other things in the code. Is this possible using the cnt someway.
Comments
Beyond 50 seconds, you have several choices. You can devote a cog to timekeeping or you can use a pair of cog counters and a spare I/O pin. One of the counters is set up to produce a 1Hz pulse on one I/O pin and the 2nd counter simply counts the 1Hz pulses. The I/O pin itself is not connected to anything.
See the application note on the counters (AN001) for details of the counter modes and the use of the counters.
Since you want the Propeller to do something when a time interval is up, you might want to use a cog to take care of the whole thing. It can use CNT to produce a 1 second down counter, then wait for the counter to go to zero, send the data, and start up the counter again ... all separate from the rest of your program and what it's doing. You may need a lock / semaphore so that this timer driven routine doesn't try to send the data while the rest of your program is changing it.
Post Edited (Mike Green) : 9/24/2009 2:07:39 PM GMT
I am not into using many cogs and other pins to keep a time value. How about this
So far its working but tends to wander after a few minutes
Generally it's best to compare time intervals like:
if (CNT - startTime) > delayPeriod
where startTime was set to CNT and delayPeriod is a delay time in clock ticks (12.5ns normally).
This limits your timing to about 25 seconds maximum. Beyond that, you have to use the cog counters or a separate cog to keep accurate time.
Post Edited (Mike Green) : 9/24/2009 2:36:22 PM GMT
you can see them as 8 separate microcontrollers inside one housing each having his own RAM (cog-RAM)
and shared HUB-RAM
Each cog has 2 32-bit-counters which can be configured different modes
best regards
Stefan