Hi ,what is the best way to get a time delay of 5 minutes.I looked in the book but still not clear. I've tried waitcnt(clkfreq*300+cnt) ....this comes up way short. Thanks-mike
The longest delay waitcnt can provide is about 56 seconds (2^32 clocks) at 80MHz. What you need to do is put a shorter wait in a repeat loop. I would suggest:
repeat 300
waitcnt(clkfreq + cnt) ' one second delay
This will be very close to a 5 minute delay, but slightly more since it does not take execution time into account.
PRI delay5Minutes | time
time := cnt
repeat 300
waitcnt(time += clkfreq) ' delay 1 second
This works by waiting for one second beyond the current time. Since all time references are relative to the initial reference to cnt, any overhead in the loop is absorbed into the wait.
Comments
This will be very close to a 5 minute delay, but slightly more since it does not take execution time into account.