Shop OBEX P1 Docs P2 Docs Learn Events
what wrong with this code? — Parallax Forums

what wrong with this code?

CrosswindsCrosswinds Posts: 182
edited 2010-01-09 00:30 in Propeller 1
Hello guys!

You probably have seen my other thread with different questions for my slotcar laptimer!

Well, i have this evening begin to dust of my spin-brain, so i have just played around a bit with it.

What Im trying to in this code, start 2 cogs, one that count 1 ms each cycle to a long, and another cog to present this value to the LCD display.

It works great when i dont assign Lane to a new cog, and just run it with passing it over to Lane. (but this aint going to cut it, since im going to have 4 different lane cogs running), and have the "present" running in its own cog.

But when it is in 2 different cogs, it counts to maybe 83 ms and then just freeze up.




Remember that this code does not reflect the finished idea, i just need to freshen up [noparse]:)[/noparse]

Comments

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2010-01-08 22:26
    Try making the space you allocate for the stacks bigger, especially the stack for present. So replace this
    [b]VAR[/b]
      [b]long[/b] Stack[noparse][[/noparse]­9]
      [b]long[/b] Stack2[noparse][[/noparse]­9]
      
      [b]long[/b] millisec
    
    
    


    with this
    [b]VAR[/b]
      [b]long[/b] Stack[noparse][[/noparse]­100]
      [b]long[/b] Stack2[noparse][[/noparse]­100]
      
      [b]long[/b] millisec
    
    
    



    If it works than you can make the 100 smaller until it works again.
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-01-08 23:14
    Steve already found your problem, I suppose?!

    In your 'present' function you call other functions of the LCD driver and you never know what these functions call themselves, maybe some private functions ... So, giving a stack of 9 longs simply is not enough and the function calls overwrite your millisec variable.

    But another thing:
    repeat 
      millisec := ++millisec 
      waitcnt (clkfreq / 1000 +cnt)
    

    this is not accurate, as you always wait for 1ms + the execution time of all instructions.

    Better is:
    waittime := cnt 
    repeat 
      millisec++ 
      waittime+=clkfreq/1000
      waitcnt( waittime ) 
    
    


    This way you always wait 1ms and the execution time of the instructions is no problem as long as it does not exceed the 1ms.

    Post Edited (MagIO2) : 1/8/2010 11:21:56 PM GMT
  • CrosswindsCrosswinds Posts: 182
    edited 2010-01-09 00:30
    Yep steven found it, and i cannot undestand why i didnt find it myself ^^ tired? hehe


    And magIO2 thanks for the input about the wait time, that will help me to pinpoint accuracy [noparse]:)[/noparse]
Sign In or Register to comment.