View Full Version : waitcnt?

01-09-2008, 04:13 AM
Why is it necessary to add 9 to Time when using waitcnt for a delay:

mov Time, cnt
add Time, #9
:loop waitcnt Time, Delay

I can't find an explanation in the Manual.


Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle

Paul Baker
01-09-2008, 04:15 AM
Because the addition of delay to time by waitcnt doesn't occur until after the wait occurs, so you need to compute the first delay before entering the waitcnt (unless you want to wait nearly a minute).

Paul Baker (mailto:pbaker@parallax.com)
Propeller Applications Engineer
[/url][url=http://www.parallax.com] (http://www.parallax.com)
Parallax, Inc. (http://www.parallax.com)

01-09-2008, 04:49 AM
see also deSilva's posting near the end http://forums.parallax.com/showthread.php?p=699845

01-09-2008, 04:56 AM
Thanks to Google I could also find an instructive example I posted some months ago (to a certain "Aempirei"), showing the working of the "instruction pipe"

deSilva said...
This is something Mike addressed:

mov Time, CNT 'Calculate delay time
add Time, #9 'Set minimum delay here
waitcnt Time, Delay 'Wait
xor OUTA, Pin

Does #9 suffice?

Yes, in fact this is the case whithout any "wait" at all (5 ticks of WAITCNT only)!

Tick GetInstr empty GetDest GetSrc Operate StoreBack
-3 MOV
-2 ---
-1 Time
+1 ADD ---
+2 --- Time
+3 Time
+4 #9
+5 WAITCNT add
+6 --- Time
+7 Time
+8 Delay
+9 Wait Time
+10 XOR
+11 ---
+12 OUTA
+13 Pin
+14 xor
+15 OUTA -> Strope detectable

I am sure aempirei ("nomen est omen") checked this out http://forums.parallax.com/images/smilies/smile.gif