Cog management, what am I doing wrong?
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]
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
[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 0I 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?
Yes.
Thanks for the help Kuroneko, autorange is now working