Shop OBEX P1 Docs P2 Docs Learn Events
Eratic Behavior while using CTR — Parallax Forums

Eratic Behavior while using CTR

DDSDDS Posts: 16
edited 2008-03-30 19:58 in Propeller 1
Help Please.

I have spent hours trying to track down the problem here.
Looking at the attached .spin file, when it runs, often within the first 20-30· cycles, it jumps ahead by thousands.
I can't use the waitcnt in this application. (I have stripped out all of the unnecessary code)

If I had to guess, I would say that the problem is timing as the cog cycles in/out of the hub.
If I get rid of the wrlong statement, it seems to work fine.
Any help would really be appreciated, I am just starting out.

Thanks,

Don

(snippet below, full spin file attached)
············· org
asm_entry
············· mov······ dira,ledport
············· mov······ seconds,#0
············· jmp······ #:LoopInit·············
:loop········
············· cmp······ hs,cnt wc······················ ' Set C=1 if cnt>hs····
······· if_nc jmp······ #:loop························· ' not done with time
:LoopInit
············· mov······ hs,cnt························· ' load 1-Second timer
············· add······ hs,CPS
············· add······ seconds,#1····················· ' Increment seconds
············· mov······ st, seconds····················
············· shl······ st, #16
············· mov······ outa,st
············· wrlong··· seconds, trigaddr·············· ' Write Value to pass-through·············
············· jmp······ #:loop

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-30 19:25
    Your problem is the comparison between hs and cnt when they have opposite signs. It's better to save the starting time of the interval and subtract that from the current time. When the result is greater than one second (CLKFREQ, not CLKFREQ/2), another second has gone by:
    asm_entry  mov  dira,ledport
                      mov  seconds,#0
    new_time   mov  hs,cnt
    loop            mov  temp,cnt
                      sub   temp,hs
                      cmp  temp,CPS  wc
         if_c        jmp  #loop
                      add   seconds,#1
                      mov  st,seconds
                      shl    st,#16
                      mov  outa,st
                      wrlong  seconds,trigaddr
                      jmp  #new_time
    
  • DDSDDS Posts: 16
    edited 2008-03-30 19:58
    Mike,

    Thanks for the solution!

    Don
Sign In or Register to comment.