P2 PASM 4xCOG Syncronize
pic18f2550
Posts: 400
I would like to know how to get 4 COGs in lockstep.
My idea is to use GETCT() to load the counter value and wait in the PASM part until it expires.
PUB main() | mode sync := GETCT() {{ Start all COGs (16sec to overflow}} sync := sync+256_000_000 * 4 {{ wait 4 sec }} cog[1] := pha1.ini(@sync, @p_array1, @s_array1, 64, 64) cog[2] := pha2.ini(@sync, @p_array2, @s_array2, 64, 64) ... DAT sync mov t0, ptra addct1 t0, #0 {{ 2 }} sync1 {{ ==== SYNC }} waitct1 {{ 2+ }} ...
Translated with www.DeepL.com/Translator (free version)
Comments
Using waitatn ?
The 4 cogs starts with waitatn, the spin code issues a cogatn(mask) with the 4-cogs bit set (after waiting a bit to allow all 4 to load and start).
Just wondering.
I still have to make some preparations in some COGs.
The syncronization comes only a little later in code.
(this is not present in the example above).
You can use a variable to signal when the cogs are waiting, same technique used with P1.
Try this:
That's pretty neat, @macca.
I used the cnt to sync all 8 cogs in a p1 logging program. For that program i needed each cog to start precisely 1 clock after each other.
PASM
Keeps the COG #2 running?
Does this also work with multiple COGs at the same time?
Yes, it's a bit-mask rather than an ID number. Value #2 is bit#1 so cog#1 gets the event. If value was #3 then cog#0 and cog#1 both get an attention event.