Shop OBEX P1 Docs P2 Docs Learn Events
Help with PE labs I/O and Timing Basics Lab... — Parallax Forums

Help with PE labs I/O and Timing Basics Lab...

RonPRonP Posts: 384
edited 2010-04-30 04:02 in Propeller 1
Hello All

Need a little help understanding something.

Page 60. Variable Example

The two global variables in the program are replaced with local variables, by removing the VAR block and adding a pipe to the method block followed by the two variables. I noticed that the LED s do the same thing but not quite exactly the same sequence. Could this be due to the local variable being long and the byte variable being short? The book explains by adding the variable to the method block it is automatically a long variable. But it doesn't explain the different behavior of the LED s. Could someone please explain it. I would like to understand this a little more before moving on in the Labs.

Thanks in advance new to the Propeller just got a few days ago. Previous experience "What's a Micro-controller" and "Boe-Bot"






'' File: ButtonShiftSpeed.spin
'' LED pattern is shifted left to right at variable speeds controlled by pushbuttons.

'' VAR

''        Byte pattern, divide

PUB     ShiftLedsLeft | pattern, divide 

        dira[noparse][[/noparse]9..4] ~~
        divide := 5

        repeat

           if pattern == 0
              pattern :=11000000

           if ina[noparse][[/noparse]22] 
              divide ++
              divide <#= 254
           elseif ina[noparse][[/noparse]21] 
              divide --
              divide #>=1

           waitcnt(clkfreq/divide + cnt)
           outa[noparse][[/noparse]9..4] := pattern
           pattern >>= 1


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Im not that bright and i can prove it.

Post Edited (RonP) : 4/30/2010 1:48:10 AM GMT

Comments

  • SSteveSSteve Posts: 808
    edited 2010-04-29 23:20
    You need to enclose your code within code tags so that we can see the indentation.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • kuronekokuroneko Posts: 3,623
    edited 2010-04-30 01:34
    Local variables with the exception of result are not initialised to 0.
  • RonPRonP Posts: 384
    edited 2010-04-30 01:47
    Sorry I fixed it in the original post. Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Im not that bright and i can prove it.
  • kuronekokuroneko Posts: 3,623
    edited 2010-04-30 03:18
    RonP said...
    Sorry I fixed it in the original post. Thanks
    OK, just verified that initialisation isn't an issue for this particular case (i.e. pattern starts with 0, but may not in a more complex program). The pattern you posted looks suspiciously like binary but somehow it's missing the leading % which would account for a different sequence. Anyway, with the % in place I can't see a difference between using global or local variables.

    Ah, I see. 11000000 decimal is %00000000_10100111_11011000_11000000 binary. So for a byte you happen to get the same pattern (%11000000), a long gives you everything else as well.

    Post Edited (kuroneko) : 4/30/2010 3:24:39 AM GMT
  • RonPRonP Posts: 384
    edited 2010-04-30 04:02
    I was missing the % binary indicator the program works without it changing the variable from byte to long made the sequence off. Now with the % the sequence remains the same byte or long variables.

    Thanks for the help kuroneko and SSteve.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Im not that bright and i can prove it.
Sign In or Register to comment.