Eratic Behavior while using CTR
DDS
Posts: 16
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
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
spin
2K
Comments
Thanks for the solution!
Don