PDA

View Full Version : Problem with BS2 _functions object?



irv
03-19-2012, 05:50 PM
I have been useing the BS2_functions object and seem to have a problem with it.
When useing the FREQOUT.Set function in three cogs ,,If the freq is set the same in two of the cogs..the
command fails,in those two cogs.If the freq commands are different the results are ok....Irv

kuroneko
03-20-2012, 01:41 AM
When useing the FREQOUT.Set function in three cogs ,,If the freq is set the same in two of the cogs..the command fails,in those two cogs.If the freq commands are different the results are ok.
I'm only guessing here (not seeing your code) but the FREQOUT_Set uses a global variable to avoid duplicated setups (e.g. if it knows that the current frequency is F then it doesn't try to re-program the counter for the next call also requesting F). Which means that when multiple cogs use the same object they affect each other. To avoid this you could either (assuming 3 cogs) include 3 instances of the BS2 functions (don't worry, only the VAR section is duplicated) or do it with two instances and use FREQOUT_SetB as well (each cog has two counters).

The following example will start 4 cogs generating the same frequency. Each cog will use its private instance of the BS2 object.

CON
_clkmode = XTAL1|PLL16X
_xinfreq = 5_000_000

OBJ
helper[4]: "BS2_Functions"

VAR
long stack[32 * 4]

PUB null | n

repeat n from 0 to 3
cognew(pulse(n, 16 + n), @stack[32 * n])

PRI pulse(idx, pin)

helper[idx].FREQOUT_Set(pin, 1{Hz}) ' start counter

waitpne(0, 0, 0) ' keep cog alive

Alternatively, you could use the Synth object instead which avoids this issue by not having duplication protection.

CON
_clkmode = XTAL1|PLL16X
_xinfreq = 5_000_000

OBJ
helper: "Synth"

VAR
long stack[32 * 4]

PUB null | n

repeat n from 0 to 3
cognew(pulse(16 + n), @stack[32 * n])

PRI pulse(pin)

helper.Synth("A", pin, 1{Hz}) ' start counter

waitpne(0, 0, 0) ' keep cog alive

irv
03-21-2012, 03:05 PM
Thanks for the response....I am now using the "synth" object.....Irv