Why dont all cogs work together?
Armondo522
Posts: 9
i want to use the prop chip to generate 8 different freq's. the toggle routine lets me know im alive. The problem is when i uncomment anymore than 2 freq.synth they all stop working. each cog works as long as only two are workin..Is there a limit to how many freq.synth can be loaded..
thanks in advance..
{
}
CON
· _CLKMODE = XTAL1 + PLL16X
· _XINFREQ = 5_000_000
· Pin·· = 0······ ' 40 hz output
· PinA· = 1······ ' 200 Hz output
· PinB· = 2······ ' 600 hz output
· PinC· = 3······ ' 1200 hz output
· PinD· = 4······· ' 10 khz
· PinE = 5······· ' 250 khz··········
· PinF =· 6········ '500 khz
· PinG =· 7········ '1 mhz·
' frequency outputs
·
· Frequency =· 40········ '···························· 'DC to 128MHz
· FrequencyA = 200········
· FrequencyB = 600······ '
· FrequencyC = 1_200
· FrequencyD = 10_000
· FrequencyE = 250_0000
· FrequencyF = 500_000
· FrequencyG = 1_000_000
·········
VAR
byte sweep_done
byte cog1
byte success
'long frequency10
'long sweep_done
long frequency1
long stack1[noparse][[/noparse]18]
long stack2[noparse][[/noparse]18]
long stack3[noparse][[/noparse]18]
long stack4[noparse][[/noparse]18]
long stack5[noparse][[/noparse]18]
OBJ
· Freq : "Synth"
····
PUB CTR_main
· DirA[noparse][[/noparse]0..7]~~·············································· ·' set all ports to output
· cognew(Toggle( 16,4_000_000,100),@stack1)···· ' indicator to show its doing something
···················· '
· cognew(FirstCtr,@stack2)····························· '40 hz & 200 Hz·
······················ '
· 'cognew(SecondCtr,@stack3)··························· '' 600 hz & 1200 hz
··
· cognew(ThirdCtr,@stack4)························· '··· 10khz & 250 khz
······················ '
·'cognew(ForthCtr,@stack5)························ ''··· 500khz & 1 mhz
repeat················································ 'loop forever to keep cog alive
PUB SecondCtr
Freq.Synth("A",PinB,FrequencyB)···· ' 600hz
Freq.Synth("B",PinC,FrequencyC)····· ' 1200hz··
repeat
PUB FirstCtr
Freq.Synth("A",0,Frequency)······ ' 40·
Freq.Synth("B",PinA,FrequencyA)····· '200
repeat
PUB Toggle(P, Delay, Count)
{{Toggle Pin, Count times with Delay clock cycles in between.}}
· dira[noparse][[/noparse]16]:=1··············· 'Set I/O pin to output direction
· repeat············· 'Repeat forever
··· !outa[noparse][[/noparse]16]·············· '· Toggle I/O Pin
··· waitcnt(Delay + cnt)···· '· Wait for Delay cycles
repeat
PUB ThirdCtr
Freq.Synth("A",PinD,FrequencyD)······ ' 10khz
Freq.Synth("B",PinE,FrequencyE)····· ' 250khz
repeat·
PUB forthCtr
Freq.Synth("A",PinF,FrequencyF)······ '500khz
Freq.Synth("B",PinG,FrequencyG)····· ' 1 mhz··
repeat······················
thanks in advance..
{
}
CON
· _CLKMODE = XTAL1 + PLL16X
· _XINFREQ = 5_000_000
· Pin·· = 0······ ' 40 hz output
· PinA· = 1······ ' 200 Hz output
· PinB· = 2······ ' 600 hz output
· PinC· = 3······ ' 1200 hz output
· PinD· = 4······· ' 10 khz
· PinE = 5······· ' 250 khz··········
· PinF =· 6········ '500 khz
· PinG =· 7········ '1 mhz·
' frequency outputs
·
· Frequency =· 40········ '···························· 'DC to 128MHz
· FrequencyA = 200········
· FrequencyB = 600······ '
· FrequencyC = 1_200
· FrequencyD = 10_000
· FrequencyE = 250_0000
· FrequencyF = 500_000
· FrequencyG = 1_000_000
·········
VAR
byte sweep_done
byte cog1
byte success
'long frequency10
'long sweep_done
long frequency1
long stack1[noparse][[/noparse]18]
long stack2[noparse][[/noparse]18]
long stack3[noparse][[/noparse]18]
long stack4[noparse][[/noparse]18]
long stack5[noparse][[/noparse]18]
OBJ
· Freq : "Synth"
····
PUB CTR_main
· DirA[noparse][[/noparse]0..7]~~·············································· ·' set all ports to output
· cognew(Toggle( 16,4_000_000,100),@stack1)···· ' indicator to show its doing something
···················· '
· cognew(FirstCtr,@stack2)····························· '40 hz & 200 Hz·
······················ '
· 'cognew(SecondCtr,@stack3)··························· '' 600 hz & 1200 hz
··
· cognew(ThirdCtr,@stack4)························· '··· 10khz & 250 khz
······················ '
·'cognew(ForthCtr,@stack5)························ ''··· 500khz & 1 mhz
repeat················································ 'loop forever to keep cog alive
PUB SecondCtr
Freq.Synth("A",PinB,FrequencyB)···· ' 600hz
Freq.Synth("B",PinC,FrequencyC)····· ' 1200hz··
repeat
PUB FirstCtr
Freq.Synth("A",0,Frequency)······ ' 40·
Freq.Synth("B",PinA,FrequencyA)····· '200
repeat
PUB Toggle(P, Delay, Count)
{{Toggle Pin, Count times with Delay clock cycles in between.}}
· dira[noparse][[/noparse]16]:=1··············· 'Set I/O pin to output direction
· repeat············· 'Repeat forever
··· !outa[noparse][[/noparse]16]·············· '· Toggle I/O Pin
··· waitcnt(Delay + cnt)···· '· Wait for Delay cycles
repeat
PUB ThirdCtr
Freq.Synth("A",PinD,FrequencyD)······ ' 10khz
Freq.Synth("B",PinE,FrequencyE)····· ' 250khz
repeat·
PUB forthCtr
Freq.Synth("A",PinF,FrequencyF)······ '500khz
Freq.Synth("B",PinG,FrequencyG)····· ' 1 mhz··
repeat······················
Comments
Problems like this are mainly caused by a too small stack.
I had a look at SYNTH and is not only has parameters, but local values, and also calls a helpr routine.
I think your program will work, when you increase the stacksizes to 25 or so...
And you need not "try". This IS the cause!
thanks again..