Shop OBEX P1 Docs P2 Docs Learn Events
Code — Parallax Forums

Code

jgonzojgonzo Posts: 5
edited 2008-06-09 13:47 in Propeller 1
PUB timer
· dira[noparse][[/noparse]1..5]~~
· outa[noparse][[/noparse]1..5]~

· repeat
··· !outa[noparse][[/noparse]1..2]
··· waitcnt(clkfreq *3· + cnt)
··· !outa[noparse][[/noparse]1..2]
··· waitcnt(clkfreq *5 + cnt)
··· !outa[noparse][[/noparse]3..5]
··· waitcnt(clkfreq *3· + cnt)
··· !outa[noparse][[/noparse]3..5]
··· waitcnt(clkfreq*5 + cnt)
··
··· I wrote this code to turn on and off 2 groups of outputs.· On for 3 seconds and off for 5 seconds, etc.

Then due to hardware logic changes I just want to invert the outputs.· So I made the following modification.

PUB timer
· dira[noparse][[/noparse]1..5]~~
· outa[noparse][[/noparse]1..5]:=1

· repeat
··· !outa[noparse][[/noparse]1..2]
··· waitcnt(clkfreq *3· + cnt)
··· !outa[noparse][[/noparse]1..2]
··· waitcnt(clkfreq *5 + cnt)
··· !outa[noparse][[/noparse]3..5]
··· waitcnt(clkfreq *3· + cnt)
··· !outa[noparse][[/noparse]3..5]
··· waitcnt(clkfreq*5 + cnt)

Only the outputs 3..5 were reversed.··Output 1..2 were not.··Can you tell me what I am doing wrong?
··

Comments

  • ColeyColey Posts: 1,110
    edited 2008-06-09 13:47
    Hi Jgonzo,

    I hope I've interpreted your requirements correctly, here is my version of your code...

    I've added some comments to the code to explain what is happening,

    Your first routine converted thus:-

    All pins start low (~) Pins 1..2 High (~~) for 3 Seconds, all pins low for 5 seconds, Pins 3..5 High for 3 Seconds, all pins low for 5 seconds, repeat ad infinitum.

    PUB timer
      dira[noparse][[/noparse]1..5]~~                   ' Make pins outputs
      outa[noparse][[/noparse]1..5]~                    ' Pins Low
     
      repeat                         ' Repeat Forever
        outa[noparse][[/noparse]1..2]~~                 ' Pins 1..2 High
        waitcnt(clkfreq *3  + cnt)   ' 3 Second Delay
        outa[noparse][[/noparse]1..2]~                  ' Pins 1..2 Low
        waitcnt(clkfreq *5 + cnt)    ' 5 Second Delay
        outa[noparse][[/noparse]3..5]~~                 ' Pins 3..5 High
        waitcnt(clkfreq *3  + cnt)   ' 3 Second Delay
        outa[noparse][[/noparse]3..5]~                  ' Pins 3..5 Low
        waitcnt(clkfreq*5 + cnt)     ' 5 Second Delay
    
    




    Your second routine:-

    Pins 1..2 start low (~) and Pins 3..5 start high (~~), Pins 1..2 High for 3 Seconds, Pins 1..2 low and Pins 3..5 remain high for 5 seconds , Pins 3..5 Low for 3 Seconds, Pins 1..2 remain low and Pins 3..5 high for 5 seconds, repeat ad infinitum.

    PUB timer
      dira[noparse][[/noparse]1..5]~~                   ' Make pins outputs
      outa[noparse][[/noparse]1..2]~                    ' Pins 1..2 Low
      outa[noparse][[/noparse]3..5]~~                   ' Pins 3..5 High
      
      repeat                         ' Repeat Forever
        outa[noparse][[/noparse]1..2]~~                 ' Pins 1..2 High
        waitcnt(clkfreq *3  + cnt)   ' 3 Second Delay
        outa[noparse][[/noparse]1..2]~                  ' Pins 1..2 Low
        waitcnt(clkfreq *5 + cnt)    ' 5 Second Delay
        outa[noparse][[/noparse]3..5]~                  ' Pins 3..5 Low
        waitcnt(clkfreq *3  + cnt)   ' 3 Second Delay
        outa[noparse][[/noparse]3..5]~~                 ' Pins 3..5 High
        waitcnt(clkfreq*5 + cnt)     ' 5 Second Delay
    
    



    I hope that helps a bit.

    Regards,

    Coley

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PropGFX Forums - The home of the Hybrid Development System and PropGFX Lite
Sign In or Register to comment.