How can I synchronize several cogs at high speed on a rise or fall edge?
Hi, This is my first ever forum entrance and as such please forgive my possible wrong doings.
Anyway.
What I want to do is to find a way to synchronize several cogs on either rising or falling edge on the pulses. I can define the period to be the same in all cogs but I would like to have the duty cycle to be as a variable among any of the cogs. As you can understand to do so I have to have the rising or the fall edge to be align with each other cod. The speeds I would like to have will be above the 50khz and most desirable at the range of Mhz's.
This is my first question of the may I would like to ask later....
Thanks
Anyway.
What I want to do is to find a way to synchronize several cogs on either rising or falling edge on the pulses. I can define the period to be the same in all cogs but I would like to have the duty cycle to be as a variable among any of the cogs. As you can understand to do so I have to have the rising or the fall edge to be align with each other cod. The speeds I would like to have will be above the 50khz and most desirable at the range of Mhz's.
This is my first question of the may I would like to ask later....
Thanks
Comments
Welcome to the forum, you will have lot's of fun with the Prop and here on the forum.
As we have no idea of tour current skill level with Spin or PASM or the Prop, or your actual application it's difficult to offer specific advice.
But here is a clue as to how synchronization of COGs can be done:
1) A master COG reads the value of the timer CNT.
2) The master adds some amount of time to the CNT value and produce a time in the future, call it T
3) The master COG starts (cognew) one or more slave COGs and passes the value of T to all of them via the PAR parameter.
4) Each slave COG starts up and does a WAITCNT waiting for the time T.
5) As all the COGs see the same system timer they will all come out of WATCNT in synchronization.
How far in the future should T be? Not sure, but enough time for the cognew calls to be made, the COGS to be loaded and started, any initial code in the COGS to be run. I would start with one second and cut it down experimentally until it breaks.
Of course the master COG can also do a WAITCNT for time T and be in synch as well.
As you want your cogs to repetitively generate pulses they will have to loop around and do that WAITCNT again, but before waiting they should all add something to T, the period that you want to have.
I would suggest experimenting with this in Spin first. If you need more speed then rework the thing in PASM.
If any of this sounds like gibberish, just ask away:)
I will try ASAP.
You gave me a good start.
More about it, as soon as I try your suggestion.
Thanks
akis
Please take a look and let me know If you agree.
PUB test_synchronization | time
time := cnt + clkfreq
ncog[0] := cognew(Freq1( 4, 10000, time), @stack[0])
ncog[1] := cognew(Freq1(12,10000, time), @stack[40])
PUB freq1(pin,freq,time)
ctra[30..26] := %00100
ctra[5..0] := pin
frqa := 0
dira[pin]~~
waitcnt(time)
frqa := NcoFrqReg(freq)
repeat
PUB NcoFrqReg(frequency) : frqReg
repeat 33
frqReg <<= 1
if frequency => clkfreq
frequency -= clkfreq
frqReg++
frequency <<= 1