how to setup a new cog?
purplemonkey
Posts: 89
if i wanted this program to run on two different cogs with two different frequencies on two different pins, how would i do it?
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
txpin = 16
freq1 = 500
freq2 = 1000
delta = 50000
txfreq = 92_500_000.0
freqb = round(txfreq * 4_294_967_296.0 / (16.0 * 80_000_000.0))
PUB main | numclks1, numclks2
dira := 1 << txpin
numclks1 := clkfreq / (2 * freq1)
numclks2 := clkfreq / (2 * freq2)
ctrb[30..26] := %00010
ctrb[25..23] := 7
ctrb[5..0] := 16
repeat
' Generate the first frequency for one-half second
repeat freq1 >> 1
frqb := freqb + delta
waitcnt(numclks1 + cnt)
frqb := freqb - delta
waitcnt(numclks1 + cnt)
' Generate the second frequency for one-half second
repeat freq2 >> 1
frqb := freqb + delta
waitcnt(numclks2 + cnt)
frqb := freqb - delta
waitcnt(numclks2 + cnt)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
txpin = 16
freq1 = 500
freq2 = 1000
delta = 50000
txfreq = 92_500_000.0
freqb = round(txfreq * 4_294_967_296.0 / (16.0 * 80_000_000.0))
PUB main | numclks1, numclks2
dira := 1 << txpin
numclks1 := clkfreq / (2 * freq1)
numclks2 := clkfreq / (2 * freq2)
ctrb[30..26] := %00010
ctrb[25..23] := 7
ctrb[5..0] := 16
repeat
' Generate the first frequency for one-half second
repeat freq1 >> 1
frqb := freqb + delta
waitcnt(numclks1 + cnt)
frqb := freqb - delta
waitcnt(numclks1 + cnt)
' Generate the second frequency for one-half second
repeat freq2 >> 1
frqb := freqb + delta
waitcnt(numclks2 + cnt)
frqb := freqb - delta
waitcnt(numclks2 + cnt)
Comments
The Propeller Education Kit Labs tutorial has several sections on using multiple cogs and on using the counters. You might have a look at it.
Spin does not do floating-point calculations inline like that, [edit]except in constant expressions, which is what you have[/edit]. You have to make method calls to one of the floating-point objects for each operation.
Finally,
-Phil
I was under the impression that the compiler would convert floating point calculations, just wont work at run time. He has it placed in the CON block so I see no reason it would not work.
And, Bits, I's so glad you're feeling well enough to correct me!
-Phil
Looks like both frequencies are the same and going to the same pin, or is that just because it's a template
Incidentally if I were to have more frequencies that meant more cogs
I've figured out to start a new cog with newcog,main@ stack command and long stack variable but how can I pass variables such as frequency and pin number with different values to different cogs? And don't you have to specify which cog?
Easy as Pi.
Since the counters run on their own they will stay at the desired frequency until you change them. Which causes me to think that I should have a way of stopping a counter. If the freq is 0 or lower, this update should do it.
if i want 2 fm frequencies each on two cogs so in total 4 frequencies how would i do that?
would i just do
newcog,Pub???@stack
set_freq("A", 48, 0) set_freq("B", 100, 1)
then just repeat this for each cog?
how do i specify which cog to run which frequencies on?
bit lost sorry, real newbie!
Here's how I called it with my test:
In the test pins P0 and P15 output 5Hz for five seconds, then I kill the cog by setting stopblinks to true. Note that for this I use the pin first, then the frequency (will probably change my set_freq() to this as well).
The worst thing you can do (in my opinion) is try to get ahead of yourself. It would probably do you a lot of good to read and work through the Propeller Education Kit manual; you can find it under the Help menu in the Propeller Tool.