Shop OBEX P1 Docs P2 Docs Learn Events
AssemblyToggle.spin — Parallax Forums

AssemblyToggle.spin

UnsoundcodeUnsoundcode Posts: 1,532
edited 2009-09-11 05:04 in Propeller 1
Hi , I have an adaptation of AssemblyToggle.spin where instead of xor'ing outa with "Pin" I am xor'ing outa with a·constant called "sData" trying to·toggle output 17.

My adaptation works the same as AssemblyToggle.spin with the exception that there is a long delay before it takes off , maybe 30 seconds.

Can someone explain why I have the delay at start up and what I have wrong or need to do to make the toggle start immediately.

I'm trying to figure out how to mask the outa register in different ways

CON
  _CLKMODE = XTAL1 + PLL16X
  _XINFREQ = 5_000_000
  
Pub main
cognew (@myasm,0)

dat
org 0
myasm
mov dira, direction
mov time,cnt 
add time,#9
mov outa,sData    
:loop  waitcnt time,delay 
xor outa,sdata
jmp #:loop
direction long |<17
sData long $AAAAAAAA  
delay   long  6_000_000
time   res 1 
fit 496


Jeff T.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-10 19:17
    The problem simply is that the first WAITCNT is waiting for a future time about 50 seconds in the future. When you read CNT, you get the time at that instant. If you add 9 clock ticks to it, that time is already nearly past. By the time you do the MOV to OUTA, the time is past and the WAITCNT has to wait until the system clock completely wraps around its 32 bit value.

    Try a larger increment to "time". I'd try at least 15. There's 1 or 2 needed for the "mov time,cnt" to finish, then 4 for the ADD and 4 for the 2nd MOV and probably 5 for the WAITCNT to start waiting.

    One "trick" is to add CNT as the last step before the WAITCNT like
            mov   time,#15
            mov   outa,sData
            add    time,CNT
    loop: waitcnt   time,delay
    

    Post Edited (Mike Green) : 9/10/2009 7:22:46 PM GMT
  • Agent420Agent420 Posts: 439
    edited 2009-09-10 19:23
    ^ Good spot.· I was thinking that it had to be a timer overflow issue, but on the surface of it 9 seemed just barely sufficient.· But then I remember reading about that interleaved command execution timing and wondering if that was causing it to fail.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-09-11 05:04
    Thanks Mike , I had read about the possibility of ·entering a value that had already passed and that the way to counter this is with offset + cnt· ( in Spin ) but didn't grasp what was happening in the assembly version.

    The original AssemblyToggle.spin from the Propeller Manual had " add Time, #9 'Set minimum delay here " which didn't make sense to me at the time but is a little clearer now.

    In my adaptation I tried #15 and it worked fine.

    A good lesson for the day.

    Jeff T.
Sign In or Register to comment.