Beginner trying to figure out a longer interval for blinking LED
fsb
Posts: 24
Probably a dumb question but I am trying to learn spin on the propeller.
I've been playing with blinking LEDs and, using the following, can get a delay up to about 50 seconds between blinks, but beyond this, the timing is way off. I was shooting for 5 minutes between blinks. What am I doing wrong?
partial code:
dira [4] := 1
repeat
outa[4] := 1
pause_ms (5000) 'msDelay = 5000
outa[4] := 0
pause_ms (50,000) 'msDelay = 50,000
PRI pause_ms (msDelay)
waitcnt (cnt + ((clkfreq/1000) * msDelay
Thanks for any help.
fsb
I've been playing with blinking LEDs and, using the following, can get a delay up to about 50 seconds between blinks, but beyond this, the timing is way off. I was shooting for 5 minutes between blinks. What am I doing wrong?
partial code:
dira [4] := 1
repeat
outa[4] := 1
pause_ms (5000) 'msDelay = 5000
outa[4] := 0
pause_ms (50,000) 'msDelay = 50,000
PRI pause_ms (msDelay)
waitcnt (cnt + ((clkfreq/1000) * msDelay
Thanks for any help.
fsb
Comments
so it's going to "repeat" for... ever...
If you are running the prop with a 5Mhz crystal and a PLL of 16 your system clock will be 80Mhz. The 32-bit width of the internal counter means you can store 0xFFFF_FFFF. When counting up at 80Mhz, that register will fill and roll-over at ~53 seconds. To get the delays you want, use cascading delays. There is also a timer object in the OBEX. When run in its own cog it can give decent timing for long periods. I don't remember the specs exactly but I think you might be able to do better than one second per day error if you have a decent crystal.
Try using the code delimiters so the spacing on your inline code is preserved [ code ] [ / code ] - remove the spaces.
Peter
PJ- I suspect that the formatting got dropped when posted. I assume they mean:
???
this is your 22nd post but anyway welcome to the propeller-forum!
You can ask whatever you want. You are asking the exact way like we (the forum-members) like it.
You tried something on your own made some success but now there is a question.
the command waitcnt uses the 32bit hardware-counter which can count up to 2^32 - 1. This is 4.294.967.295
Each clock-tick of the propeller the counter increments by one. This means for counting up to 4.294.967.295 at a clockfrequency of 80MHz means after
4.294.967.295 / 80.000.000 = 53.68 seconds the counter has counted up to his maximum.
The waitcnt command works that way: the execution of the cog is stopped until the new value is matched.
If you try to wait for more than 53 seconds the value does not match after the amount of time it should because
the counter can't count up to a 33-bitvalue wich would be nescessary to count up to 60 seconds
This works always even if the counter is almost at his maximum as he just wraps around to zero and starts counting up again
until the value matches. you can imagine this like a milecounter in a car if it is at its max it wraps around to zero and starts counting up again
if you code a waitcnt-command this means take actual number of counter and add a certain number (if this means exceeding the max value
it counts up to max and then to the rest of the "distance"
If you want to blink slower or wnat to wait longer you have to divide the waiting into pieces smaller than 53 seconds
and do more than one waitcnt command
in the obex there is a timer object which provides a realtime clock that offers form milliseconds up to years.
also start reading the manual about the command waitcnt and the systemcounter "CNT" If you don't understand
anything from the manual came back with questions
best regards
Stefan
StefanL38's suggestion about the manual is a great one. In the downloadable version of the prop manual (available on the Parallax website) there is a good section on using waitcnt. Page 219 is a good place to start.