Execution dying while scrambling serial debugger
I have some code that calls an object in a new cog, but calling the cog causes the rest of the code in the original cog to halt execution. When I use the serial debugger to try and debug, I get a bunch of nonsense in the output. Here is the code for the calling cog:
I tried making cogStack1's length higher in the calling code, but that didn't change anything. Any suggestions? It may be something obvious, I've only been propelling for a couple months now. Thanks for the help.
con
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
obj
sinsynth : "sintabsynth"
sawsynth : "sawtabsynth"
trisynth : "triangletabsynth"
squaresynth:"squaretabsynth"
keyReader:"keyReader"
DDS : "DDS_PASM"
Debug : "FullDuplexSerial"
var
byte cog1
long cogStack1[50]
long playFreqs[5]
long playPress[5]
byte t1
pub main
Debug.start(31,30,0,57600)
waitcnt(clkfreq*4 + cnt)
Debug.str(string("trying strings", $D))
cog1 := cognew(keyReader.Main(@playFreqs, @playPress), @cogStack1) + 1
repeat
t1 := 0
repeat while t1 < 6
Debug.dec(playFreqs[t1])
t1++
waitcnt(clkfreq/6 + cnt)
and here is the code that is causing the problem, which is the code that is loaded in the cog called by the code above:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
threshold = 300
OBJ
AD_DRVR : "MCP3208_DRIVER"
Debug : "FullDuplexSerial"
VAR 'options: long, word or byte
byte keyRef
byte playRef
byte lowPlayKey 'lowest playset key pointer
byte t1
byte t2
byte t3
byte t4
byte t5
byte highestKeyIndex
byte adc
long keyReadings[24]
long cogStack[10]
byte cog
'long highestKeyReading
PUB Main(playFreqs, playPress)
Debug.start(31,30,0,57600)
waitcnt(clkfreq*4 + cnt)
Debug.str(string("trying strings2", $D))
cog := cognew(GetKeyReadings, @cogStack) + 1
repeat
keyRef := 0
repeat while keyRef < 25 'iterate through key readings
if keyReadings[keyRef] > threshold 'check if above the threshold
playref := 0
t1 := 0
repeat while playRef < 6 'now determine if key is already in playset
if long[@Freqs][keyRef] == long[playFreqs][playRef]
t1 := 1
quit
playRef++
if t1 == 1 'if key is already in the playset....
long[playPress][playRef] := keyReadings[keyRef] 'then update the pressure
else 'if key is not already in the playset
playRef := 0
t1 := 0
repeat while playRef < 6 'determine if there are 6 keys already in the playset
if long[playFreqs][playRef] == 0
t1 := 1
quit
playRef++
if t1 == 1 'if there aren't 6 keys already in the playset..
long[playFreqs][playRef] := long[@Freqs][keyRef] 'then add the key freq and pressure to the playset
long[playPress][playRef] := keyReadings[keyRef]
else 'if there are 6 keys already in the playset...
playRef := 0 'then find lowest key in the playset
t1 := 0
t2 := 4095
repeat while playRef < 6
t1 := long[playPress][playRef]
if t1 < t2
t2 := t1
't5 := playRef
playRef++
long[playFreqs][t2] := long[@Freqs][keyRef] 't2 now has the lowest key, so replace it using keyRef
long[playPress][t2] := keyReadings[keyRef]
else 'keyReading is not above threshold
playref := 0
t1 := 0
repeat while playRef < 6 'determine if key is already in playset
if long[@Freqs][keyRef] == long[playFreqs][playRef]
t1 := 1
quit
playRef++
if t1 == 1 'if it's in the playset
long[playPress][playRef] := 0 'then delete it
long[playPress][playRef] := 0
keyRef++
PUB GetKeyReadings
repeat
t3 := 0 'keeps track of the key we're reading
adc := 0 'keeps track of the adc IC we're reading from
repeat while adc =< 3
if adc == 0
AD_DRVR.start(21,20,19,0)
elseif adc == 1
AD_DRVR.start(18,17,16,0)
elseif adc == 2
AD_DRVR.start(13,14,15,0)
elseif adc == 3
AD_DRVR.start(10,11,12,0)
t4 := 0 'keeps track of the adc channel we're reading from
repeat while t4=<7
if (adc==1 AND t4>3) OR (adc==3 AND t4>4)
quit
keyReadings[t3] := AD_DRVR.in(t4)
t4++
t3++
adc++
DAT
'Define the frequencies for the middle octave
Freqs long 523,494,466,440,415,392,369,349,330,311,294,277,262,247,233,220,208,196,185,175,165,156,147,139,131
I tried making cogStack1's length higher in the calling code, but that didn't change anything. Any suggestions? It may be something obvious, I've only been propelling for a couple months now. Thanks for the help.

Comments
form a quick look at your code I can say starting the FullDuplexSerial-object in two different cogs must end in mixed up nonsense-output
the two cogs run independent from each other say both are trying to send characters at the same time which mixes up the output completely.
for debugging you could use the EZLog-tool from hannoware http://hannoware.com/ezlog/
It allows to monitor variables while your code is running in the same way as without watching them.
This is possible beause EZLog starts an independent working cog to transfer the debug-data
best regards
Stefan