Shop OBEX P1 Docs P2 Docs Learn Events
Assembly: waitcnt - trouble — Parallax Forums

Assembly: waitcnt - trouble

T. SalewskyT. Salewsky Posts: 3
edited 2007-01-18 14:57 in Propeller 1
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?

Comments

  • rokickirokicki Posts: 1,000
    edited 2007-01-16 19:35
    You need to examine how the assembly waitcnt instructions works some more.

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-16 19:36
    The Delay applies to the second waitcnt. The first waits until cnt+9 occurs (not much time), then adds Delay to the Time. The second waitcnt waits for cnt+9+Delay to occur and leaves Time set to cnt+9+Delay+Delay. I think what you want is to move ":loop" to after the "add".
  • T. SalewskyT. Salewsky Posts: 3
    edited 2007-01-18 14:57
    Thank you, now i understand.
Sign In or Register to comment.