Problem with "Pause"
dar
Posts: 15
Hi, i have a little problem, i want to pause a minute i'm trying to do it using:
clk.PauseSec(60) with "clock" object, but it don't works it pause a few seconds, however if i pause 10 or 20 seconds it works fine.
Can you explain me why it happens?
Now to pause a minute i'm doing with a loop:
repeat 3
clk.PauseSec(20)
But i want to do it correctly, i'm reading now how "waitcnt" works to try to do the correct pause.
Thanks.
clk.PauseSec(60) with "clock" object, but it don't works it pause a few seconds, however if i pause 10 or 20 seconds it works fine.
Can you explain me why it happens?
Now to pause a minute i'm doing with a loop:
repeat 3
clk.PauseSec(20)
But i want to do it correctly, i'm reading now how "waitcnt" works to try to do the correct pause.
Thanks.
Comments
It looks like this pauseSec funktion works with the cnt and does not take into account that cnt wraps around after somewhat around 50 seconds. So if you don't want to fix this object, your workaround is the right thing to do.
2^31 milliseconds works out to just under 25 days!
The pause method is supported by a compile-time constant MS_001, which is defined at the top of my template:
I've attached the code I use as my template -- it's easy enough to chop out any unused methods.
with waitcnt for example to wait a seconds can i use:
waitcnt(CLK_FREQ cnt)
and use a loop to wait 60 seconds?
Thanks for the code, i will look it to learn and understand how it works to do the pause!!!
As you suggest, use a loop of second long waits.
You could wait one minute this way:
You'll need to use the loop method to wait longer than the counters reset time. (IIRC, @80MHz the counter rolls over in about 2 minutes 54 seconds.)
The above waits aren't exact. They'll be off a bit since it take time to execute the code to setup the wait. I believe JonnyMac's code takes this overhead into account (that's why he uses "- 1776").
Thanks for the suggestion!, but if i use:
How i know when is the counters reset time?
If i want to wait 5 minutes can i use:
As I said in my first answer, the limit is somewhere around 50 seconds.
(2^32-1) / 80_000_000 to be exact.
That's why you have to break down bigger wait-times into 1s wait-statements or 10s wait-statements.
Even breaking down to milliseconds gives a usable span of delays. To pause four one minute:
I like to use the underscore character where a comma would normally go when writing out a large number.
You're of course right. I should have known that.
Edit: Apparently I was remembering incorrectly about the roll over time. It's not over two minutes, it's less than one. About 53 seconds.
32 bits has 4,294,967,295 possible values. Divide this by 80,000,000 (clock cycles in one second at 80MHz) and you get 53 (rounded down to nearest second).