Shop OBEX P1 Docs P2 Docs Learn Events
Why dont all cogs work together? — Parallax Forums

Why dont all cogs work together?

Armondo522Armondo522 Posts: 9
edited 2007-10-22 17:25 in Propeller 1
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..smhair.gif

{


}
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

  • deSilvadeSilva Posts: 2,967
    edited 2007-10-19 22:21
    There is no obvious bug in your code....
    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...
  • Armondo522Armondo522 Posts: 9
    edited 2007-10-19 22:26
    will try it monday..· thanks for quick response..
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-19 22:29
    It was not so quick smile.gif I tried to spot an error...
    And you need not "try". This IS the cause!
  • Armondo522Armondo522 Posts: 9
    edited 2007-10-22 16:51
    Works like a champ...thanks a E6... How are you supposed to figure out the correct size of the stack???



    thanks again..
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-22 17:25
    You have to figure out the deepest call nesting (one routine calling another without returning). Figure 3 longs (maybe 4) for each call plus one for each parameter in the calls and each local variable defined. If the calls are function calls and they occur in expressions, you have to figure in the number of temporary values needed. Add a few more "just in case" and there you have it! 20 is generally a minimum unless you carefully consider what's really needed. Often I'd double that. There is a program in the Object Exchange that fills the stack area for a new cog with some unique marker value, then continually watches the stack area to see how many longs with this unique value are overwritten. That will give you a good approximation of what's actually needed.
Sign In or Register to comment.