Shop OBEX P1 Docs P2 Docs Learn Events
New variables not zero and zeroing them causes problems. — Parallax Forums

New variables not zero and zeroing them causes problems.

sccoupesccoupe Posts: 118
edited 2014-06-01 17:01 in Propeller 1
I am having some issues with new variable arrays. It seems like maybe they are overlapping code space but as you can see there is plenty of ram left. If a new 'long VariableID[100]' is created in the VAR section and then read, each long seems to already have a random number in it. Should these not be zero when they are declared? To further the issue, if I manually zero these values at the beginning of the object, the whole program locks up. Any ideas here?

ram.jpg
319 x 164 - 17K
ram.jpg 17.2K

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-06-01 15:40
    sccoupe wrote: »
    Any ideas here?

    You have a problem in your code.

    Yes, variables declared in the VAR section will have the initial value of zero. Some part of your code is overwriting these values.

    We won't be able to help much without seeing the code.
  • sccoupesccoupe Posts: 118
    edited 2014-06-01 16:16
    CON
      _clkmode = xtal1 + pll16x                                                   
      _xinfreq = 5_000_000
    
    VAR
    
      long  ID2[100]
    
    OBJ
    
      FDS    : "FullDuplexSerial"
      
    PUB Main | a
    
       FDS.start(31,30,0,115_200)
    
    
    repeat
      FDS.HEX(long[ID2][1],8)
      waitcnt(cnt + clkfreq)
    
    

    This returns a value that is not zero.
  • kuronekokuroneko Posts: 3,623
    edited 2014-06-01 16:18
    As expected (more or less). Either use ID2[1] or long[@ID2][1].
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-06-01 16:35
    Having done this myself many times, I can tell you the reason zeroing the variable was causing you trouble was because instead of zeroing the variable you were overwriting the clock settings of the Propeller (around address 0).

    I like using the first solution kuroneko suggested. IMO, the first notation looks cleaner than the second.

    Remember the elements of your array are numbered 0 through 99. So the first element is ID2[0].
  • sccoupesccoupe Posts: 118
    edited 2014-06-01 17:01
    THANKS!!! This cost me a day but maybe never make the mistake again. Between that and using := in an if statement instead of == and then the compiler(and my eyes) not catching a few double brackets, it all working now.
Sign In or Register to comment.