Weird problem with multiple cogs
ryfitzger227
Posts: 99
I'm running multiple cogs and I'm experiencing some weird problems. It might just be me, since I'm fairly new to the propeller, but I would like you guys to check just in case.
Here's my code I have at the moment
You'll notice that under start subroutine the last 3 cognews are commented out. That's because I'm trying to take this one timer at a time. Now, if I comment out one line (either the ET Timer or 60ft Timer cognew) the program runs as it should, but if I have both of those lines the way they are now it completely skips the line repeat until BYTE[readyadr] == 1 'Don't monitor pin status until the computer is ready for timing in the mainFinish subroutine and doesn't even poll in the main subroutine. I tried increasing the stack variable, but that didn't work. I'm really lost as to what this could be. Do you see any errors in my code that could make this happen?
Here's my code I have at the moment
VAR long stack[10] PUB start(t1a, t2a, t3a, t4a, t5a, readya, xfirsta) cognew(mainFinish(t1a, 5, 4, readya, 24, xfirsta), @stack) ' ET Timer cognew(main(t2a, 5, 0, readya, 24), @stack) ' 60 Ft Timer 'cognew(main(t3a, 1, 2, readya, 24), @stack) ' 330 Ft MPH Timer 'cognew(main(t4a, 5, 2, readya, 24), @stack) ' 330 Ft Timer 'cognew(main(t5a, 3, 4, readya, 24), @stack) ' MPH Timer PUB main(tadr, tstart, tstop, readyadr, manstop) : ticks | mask1, mask2 '--SETTING MASKS FOR WAITPNE-- mask1 := |<tstart + |<manstop 'manstop is the pin number that the serial object sets on manual stop mask2 := |<tstop + |<manstop repeat 'main repeat repeat until BYTE[readyadr] == 1 'Don't monitor pin status until the computer is ready for timing waitpne(0,mask1,0) 'wait for start infrared to be broken (tstart=1 or manstop=1) ticks := cnt 'get timer value dira[16] := 1 outa[16] := 1 waitpne(0,mask2,0) 'wait for stop infrared to be broken (tstop=1 or manstop=1) LONG[tadr] := cnt - ticks 'calculate the final result if ina[manstop] 'if manual stop was set dira[manstop] := 1'reset manual stop.. outa[manstop] := 0'... repeat until BYTE[readyadr] == 0 ' Don't continue until the computer says the timing is over PUB mainFinish(tadr, tstart, tstop, readyadr, manstop, xfirstadr) : ticks | mask1, mask2 '--SETTING MASKS FOR WAITPNE-- mask1 := |<tstart + |<manstop 'manstop is the pin number that the serial object sets on manual stop mask2 := |<tstop + |<manstop repeat 'main repeat repeat until BYTE[readyadr] == 1 'Don't monitor pin status until the computer is ready for timing waitpne(0,mask1,0) 'wait for start infrared to be broken (tstart=1 or manstop=1) ticks := cnt 'get timer value dira[17] := 1 outa[17] := 1 waitpne(0,mask2,0) 'wait for stop infrared to be broken (tstop=1 or manstop=1) LONG[tadr] := cnt - ticks 'calculate the final result '--FINISH LINE ONLY-- if ina[6] == 0 'see if other lane has already crossed dira[7] := 1 'tell other lane that this lane crossed first.. outa[7] := 1 '... LONG[xfirstadr] := 1 'tell computer that this lane crossed first else LONG[xfirstadr] := 2 'continue... this lane didn't cross first. if ina[manstop] 'if manual stop was set dira[manstop] := 1'reset manual stop.. outa[manstop] := 0'... repeat until BYTE[readyadr] == 0 ' Don't continue until the computer says the timing is over
You'll notice that under start subroutine the last 3 cognews are commented out. That's because I'm trying to take this one timer at a time. Now, if I comment out one line (either the ET Timer or 60ft Timer cognew) the program runs as it should, but if I have both of those lines the way they are now it completely skips the line repeat until BYTE[readyadr] == 1 'Don't monitor pin status until the computer is ready for timing in the mainFinish subroutine and doesn't even poll in the main subroutine. I tried increasing the stack variable, but that didn't work. I'm really lost as to what this could be. Do you see any errors in my code that could make this happen?
Comments
I'm not sure what you're trying to do here:
Does the button/switch get reset this way? If so, don't you need to set the pin back to an input after the reset?
Maybe I'm premature with this observation since it sounds like you're trying to figure out how to launch the cogs you need before you attend to these other details.
Be aware if one cog sets either "dira" or "outa" high a different cog isn't going to be able to change the state of the I/O pin. Each cog has a "dira" and "out" register and these registers are logically "or"ed together to determine the pins' state.
As in this example I'm using ... I take great care not to call any external routines. It operates perfectly. However, I'm not really sure how much stack I need? Or how to estimate it from any of the documentation for the propeller?
... Tim
Here's a couple of methods from the FAT SD card driver.
I've noticed methods that only call one method use three additional stack longs than the final method called.
For example "readLong" requires 35 longs while the method "readLong" calls "readData" requires 32 longs.
I don't know how Kye figures out how much stack each method uses but it sure looks like he can do it pretty precisely.