Assembly: waitcnt - trouble
Hi all,
i have a little problem with waitcnt in assembly.
The following assembly code runs good.
It Toggles with a period of 1,0 s.
con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
var
long stack[noparse][[/noparse]60]
pub Toggle_Main
cognew (@Toggle, stack)
dat
org 0
Toggle
mov dira, Pin ' P0 als output
:loop
mov Time, cnt
add Time, #9
waitcnt Time, Delay
waitcnt Time, Delay
xor outa, Pin
jmp :loop
'
Pin long |<0 | |<16
Delay long 40_000_000 'wait 0,5 s
Time res 1
'##########################################
But if i use waitcnt only 1 time -- it will never wait. It Toggles with a Preiode of 2,1 micro sec.
see next.
con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
var
long stack[noparse][[/noparse]60]
pub Toggle_Main
cognew (@Toggle, stack)
dat
org 0
Toggle
mov dira, Pin ' P0 als output
:loop
mov Time, cnt
add Time, #9
waitcnt Time, Delay
xor outa, Pin
jmp :loop
'
Pin long |<0 | |<16
Delay long 40_000_000 'wait 0,5 s
Time res 1
'##########################################
-- WHY? I dont understand, but i want to understand.
Is there anyone on earth who can help me?
i have a little problem with waitcnt in assembly.
The following assembly code runs good.
It Toggles with a period of 1,0 s.
con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
var
long stack[noparse][[/noparse]60]
pub Toggle_Main
cognew (@Toggle, stack)
dat
org 0
Toggle
mov dira, Pin ' P0 als output
:loop
mov Time, cnt
add Time, #9
waitcnt Time, Delay
waitcnt Time, Delay
xor outa, Pin
jmp :loop
'
Pin long |<0 | |<16
Delay long 40_000_000 'wait 0,5 s
Time res 1
'##########################################
But if i use waitcnt only 1 time -- it will never wait. It Toggles with a Preiode of 2,1 micro sec.
see next.
con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
var
long stack[noparse][[/noparse]60]
pub Toggle_Main
cognew (@Toggle, stack)
dat
org 0
Toggle
mov dira, Pin ' P0 als output
:loop
mov Time, cnt
add Time, #9
waitcnt Time, Delay
xor outa, Pin
jmp :loop
'
Pin long |<0 | |<16
Delay long 40_000_000 'wait 0,5 s
Time res 1
'##########################################
-- WHY? I dont understand, but i want to understand.
Is there anyone on earth who can help me?

Comments
waitcnt dest, src
waits until the time in dest, *then* adds src to dest.
So your code should be more like:
(head of loop):
mov Time,cnt
add Time,Delay
loop:
...
waitcnt Time,Delay ' this waits, and updates the time for the next time
xor outa, Pin
jmp :loop