Shop OBEX P1 Docs P2 Docs Learn Events
Cognew in PASM — Parallax Forums

Cognew in PASM

gambrinogambrino Posts: 28
edited 2008-11-14 00:38 in Propeller 1
Hello , i read the Propeller programming tutorial and i played the exercises , and i feel that something i didn't understood it good.
1)Can one cog toggle 2 pins simultaneously ? or i should use the parallel processing?
2)How can i toggle 2 pins simultaneously in PASM ? using cognew ? can i write like this to toggle pin16 and 17 simultaneously ? :
{{ AssemblyToggle.spin }}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB Main
cognew(@Toggle, 0) 
DAT

        ORG 0 

Toggle  mov dira, Pin 
        mov Time, cnt 
        add Time, #9 
:loop   waitcnt Time, Delay 
        xor outa, Pin 
        jmp #:loop 

Toggle1 mov dira, Pin1 
        mov Time, cnt 
        add Time, #9 
:loop   waitcnt Time, Delay 
        xor outa, Pin1 
        jmp #:loop 
        
Pin long |< 16 
Pin1 long |< 17 
Delay long 80_000 
Time res 1 




Thank you for your help

Comments

  • HarleyHarley Posts: 997
    edited 2008-11-13 18:19
    I too have that need, gambrino. Here was my approach; probably got the clue from off this forum:

    Using a 'temp' register, I've used this
       xor   temp, OUTA  ' combine with pin states
       xor   OUTA, temp  ' then set/clear for desired output
    
    


    Possibly there are better or faster schemes. I'd welcome any myself. yeah.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
  • AribaAriba Posts: 2,690
    edited 2008-11-14 00:38
    To toggle P16 + P17 simultaneously:
    {{ AssemblyToggle.spin }}
    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    PUB Main
    cognew(@Toggle, 0) 
    DAT
    
            ORG 0 
    
    Toggle  mov dira, Pins 
            mov Time, cnt 
            add Time, #9 
    :loop   waitcnt Time, Delay 
            xor outa, Pins 
            jmp #:loop 
    
    Pins long 1<<16 | 1<<17   'PinMask (set all Pins to 1 which should toggle)
    Delay long 80_000 
    Time res 1 
    
    


    XOR toggles all Pins which have the Bit set in the Pin Mask. You can toggle 1 to 32 Pins with one XOR.
    1<<16 (or |<16) is a more readable form of writing %00000000000000010000000000000000 but in this binary
    form, you can see how every bit0..31 of the mask corresponds to a pin PA0..PA31 on the Port.

    In PASM all bithandling is done with Bitmasks. Use
    XOR to toggle the bits (pins)
    OR to set the bits (pins)
    ANDN to clear the bits (pins)
    MUXxx to set the bits according the C or Z flag value.

    Andy
Sign In or Register to comment.