Shop OBEX P1 Docs P2 Docs Learn Events
Toggling pins on/off in PASM — Parallax Forums

Toggling pins on/off in PASM

PhilldapillPhilldapill Posts: 1,283
edited 2008-07-01 03:39 in Propeller 1
How do you toggle a pin on and off in PASM? Is there an equivalent of OUTA[noparse]/noparse in PASM?

Comments

  • TimmooreTimmoore Posts: 1,031
    edited 2008-06-30 23:02
    translate pins to pin masks then use

    or outa, mask
    andn outa,mask
  • ColeyColey Posts: 1,110
    edited 2008-06-30 23:03
    mov     dira,#1  
    mov     outa,#1
    
    



    Turns on P0

    Use it with a pin mask to turn on a specific pin eg outa, #1 <<16 would turn on P16

    Regards,

    Coley

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PropGFX Forums - The home of the Hybrid Development System and PropGFX Lite

    Post Edited (Coley) : 6/30/2008 11:51:41 PM GMT
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-06-30 23:20
    Perfect. Thanks guys!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-06-30 23:29
    Coley said...
    Use it with a pin mask to turn on a specific pin eg outa, #1 <<16 would turn on P16
    Actually, it would not. Immediate operands are limited to values between 0 and $1ff, so 1 << 16 is out of range. But you can still use indirect addressing:

            or      dira,mask16    'Set pin as an output.
            or      outa,mask16    'Turn pin on.
            andn    outa,mask16    'Turn pin off.
            xor     outa,mask16    'Toggle pin.
    
    mask16  long    1 << 16
    
    
    



    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!

    Post Edited (Phil Pilgrim (PhiPi)) : 6/30/2008 11:36:04 PM GMT
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-06-30 23:32
    haha, that's funny you posted this Phil. I was just trying that and would get an error saying the source must be less than $1FF. I was just about to post an "er?" question. Thanks!
  • TimmooreTimmoore Posts: 1,031
    edited 2008-06-30 23:35
    The other thing to be careful with using mov for outa, is if the cog has more than 1 output pin, the mov outa affects them all, i.e. the others are set to 0. Its great if thats what you want but often you only want to affect 1 pin.
  • ColeyColey Posts: 1,110
    edited 2008-06-30 23:47
    DAT
    
    Led        mov     _mask,#1              
               shl      _mask,#16
               mov     dira,_mask
               mov     outa,_mask
    
    _mask      res      1 
    
    



    Oops, my bad!

    This does work though! blush.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PropGFX Forums - The home of the Hybrid Development System and PropGFX Lite
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-07-01 00:02
    Well, I'm excited. My first ever PASM program! yay!

    org
    entry   or dira, pinOut
            mov time, cnt
            add time, duty
            mov invduty, period
            sub invduty, duty         
            jmp #:loop
    
    :loop   waitcnt time, invduty
            or outa, pinOut
            waitcnt time, duty
            xor outa, pinOut
            jmp #:loop                     'loop for next cycle  
     
    period  long  8000
    duty    long  7000
    invduty res 1                     
    time    res 1
    value   res 1
    t1      res 1
    pinOut  long 1<<15
    ctraval res 1
    

    ·
  • TimmooreTimmoore Posts: 1,031
    edited 2008-07-01 00:09
    res must be the last thing. pinout needs to be moved earlier.
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-07-01 00:17
    Oops! You're right. Fixed it.

    Now I have a question... If I set the period to 80,000, the frequency should be 1kHz, right? No. My meter says it's ~166Hz... pretty off if you ask me...
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-07-01 01:46
    Ok, so now the question is, how do you use an "if this, then do that" statement in PASM?

    I need to see some incremental count has reached a threshold, then do something else.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-07-01 03:39
    Look at tjz, tjnz for 0 and non-0, djnz, test and cmp instructions
    you test and cmp you need to specify to set wz or wc
    then you can use
    cmp t0,#4 wz
    if_z jmp #equal4

    it compares t0 to 4 sets the wz flag if they are the same.
    if_z says execute the instruction if the wz flag is set, so you would execute the jmp otherwise its a nop

    you can set the flags on most instructions and you can use if_z etc on most instructions, so for example

    cmp t0,#4 wz
    if_z mov t0, #0

    would set t0 to 0 if it was 4
    I would take a look through fullduplexserial, its a pretty good straightforward piece of pasm that is complex enough to show a lot of stuff. (I would not look at my version of fullduplexserial4fc, I was trying to push the prop and so it re-writes the code on the fly - not just source/dest addresses but the instructions, etc. Once you get used to pasm take a look at some of the stuff you can do if you really want but it does make the code a lot harder for anyone to understand)
Sign In or Register to comment.