Shop OBEX P1 Docs P2 Docs Learn Events
Cog management, what am I doing wrong? — Parallax Forums

Cog management, what am I doing wrong?

turbosupraturbosupra Posts: 1,088
edited 2012-06-25 20:03 in Propeller 1
I'm using the following code snippet posted below.

As you'll see in the video, when I type in autorange=1 into the pst, the first statement is evaluated to true and cognew launches the method right underneath of it.

You'll then see my pst screen go haywire, although you'll also see the code working.

Then I'll type autorange=0 and you'll see the screen stop flickering, but if you notice the cog is still running because the rpm value is still incrementing in the upper right hand corner.

So my question is, what am I doing wrong with cognew and cogstop. I believe it is trying to start and stop the cog each loop of Pub Main and that this is something simple I am overlooking. This is the first time I've tried to launch a cog outside of when the program initially launches and the first time I've tried to use cogstop as well. I made a screen cap video of how the screen is flickering and put it on youtube to show what I am talking about.


[video=youtube_share;wa_A3u8SI70]

PUB Main

  repeat



    pstCom

    'mafsim


    {l_prevTime := l_currTime
    l_currTime := cnt
    charAt( 20, 45, " " )  ' ("loopTime:") )
    pst.dec(l_currTime-l_prevTime)
    pst.str(@spaces)}

    if (l_autoRange == 1) and (l_autoRangingNow == false)
      if(l_cogSimRealWorld == -7)  ' set to -7 upon initialization until an actual cog number is assigned to it
        'l_rpm := 0
        l_autoRangingNow := true
        l_rpmDirection := string("up") 
        l_cogSimRealWorld := cognew(simulateRealWorld, @simulateRealWorld_Stack) + 1
        charAt( 20, 46, " " )  ' ("loopTime:") )
        pst.dec(-7777777)
        pst.str(@spaces)

    if (l_autoRange == 0) and (l_autoRangingNow == true) 
      if(l_cogSimRealWorld <> -7)
        cogstop(l_cogSimRealWorld)
        l_autoRangingNow := false
        l_cogSimRealWorld := -7  ' set back to -7 instead of 0, indicating it is not cog 0



PUB simulateRealWorld

  repeat

    

    'if (l_rpmDirection == string("up"))
      l_rpm += 25

    if (l_rpmDirection == string("down"))
      l_rpm -= 25  

    if (l_rpm < 50)
      l_rpmDirection := string("up")
      
    if (l_rpm > 9000)
      l_rpmDirection := string("down")

        
    l_autoRanging := string("true")
    ' target cam angle
    ' target maf value
    waitcnt((clkfreq/4) + cnt)
      
      

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2012-06-25 18:21
    Right now you're not stopping the cog you were starting. The +1 is usually used to get a TRUE/FALSE indication of whether cognew succeeded. As this isn't (but maybe should be) used here removing the +1 should make things work.
            [COLOR="blue"]l_cogSimRealWorld := cognew(simulateRealWorld, @simulateRealWorld_Stack)[/COLOR][B][COLOR="red"] + 1[/COLOR][/B]
            charAt( 20, 46, " " )  ' ("loopTime:") )
            pst.dec(-7777777)
            pst.str(@spaces)
    
        if (l_autoRange == 0) and (l_autoRangingNow == true) 
          if(l_cogSimRealWorld <> -7)
            [COLOR="blue"]cogstop(l_cogSimRealWorld)[/COLOR]
            l_autoRangingNow := false
            l_cogSimRealWorld := -7  ' set back to -7 instead of 0, indicating it is not cog 0
    
  • turbosupraturbosupra Posts: 1,088
    edited 2012-06-25 18:37
    Thank you, that worked for the cog stop but it did not help with the screen flicker. Do you have any idea what could be causing that?

    I guess I could also do cogstop(l_cogSimRealWorld-1)? So I don't have to go back and change the format of how I'm tracking which cogs are being used?
  • kuronekokuroneko Posts: 3,623
    edited 2012-06-25 18:50
    turbosupra wrote: »
    Thank you, that worked for the cog stop but it did not help with the screen flicker. Do you have any idea what could be causing that?
    Your guess is as good as mine. That said, note that using string("foo") multiple times will give you multiple copies of that string. Which also means your comparisons don't work as you'd expect them to (big assumption on my part). I'd suggest using DAT strings and refer to them instead (or just use numeric values). Since stopping the cog affected by this solves the screen issue it suggests a (vague) connection.
    turbosupra wrote: »
    I guess I could also do cogstop(l_cogSimRealWorld-1)?
    Yes.
  • turbosupraturbosupra Posts: 1,088
    edited 2012-06-25 19:12
    Thanks I will lose the strings and use numbers :)
  • turbosupraturbosupra Posts: 1,088
    edited 2012-06-25 20:03
    It turns out elsewhere in the code I had pst.str([numericvalue]) and that was causing the flicker.

    Thanks for the help Kuroneko, autorange is now working
Sign In or Register to comment.