Shop OBEX P1 Docs P2 Docs Learn Events
Counter Question ... Near-Simultaneously read counters from 7 cogs — Parallax Forums

Counter Question ... Near-Simultaneously read counters from 7 cogs

groggorygroggory Posts: 205
edited 2012-06-21 14:58 in Propeller 1
So let's say I have 7 different clock sources fed into the propeller. I start 7 cogs and tell each cog to listen to one of the clocks on one of its counters and increment that counter on each up-tick.

Is there a way that the 8th's cog could do something so that it can get a point-in-time look at all 7 counters? I don't know ASM, but I know spin relatively well. I need to know the counts at as close to the same time as possible.

I know there are some other ways to tackle this, but I'm purposefully doing this in 7 counts because this problem is part of a much larger problem I'm working on. So please don't advise me to use both the counters for each cog or things like that.

Thank you very much for the sage advise I know you'll bestow on me.

Comments

  • jazzedjazzed Posts: 11,803
    edited 2012-06-21 12:12
    groggory wrote: »
    So let's say I have 7 different clock sources fed into the propeller. I start 7 cogs and tell each cog to listen to one of the clocks on one of its counters and increment that counter on each up-tick.

    Is there a way that the 8th's cog could do something so that it can get a point-in-time look at all 7 counters? I don't know ASM, but I know spin relatively well. I need to know the counts at as close to the same time as possible.

    I know there are some other ways to tackle this, but I'm purposefully doing this in 7 counts because this problem is part of a much larger problem I'm working on. So please don't advise me to use both the counters for each cog or things like that.

    Thank you very much for the sage advise I know you'll bestow on me.

    The 8th COG will have to monitor what the other 7 produce in some mailbox locations. It is possible to pass a future CNT to all COGs at startup and make them synchronize their operation to it within a hub time for all (16 clock ticks). There are different ways snapshot and deliver the information. One way is for the COG code to look at phsa/b for changes in each COG and snap the time to a register then write that to the HUB RAM mailbox. The 8th COG could just poll the mail boxes or optionally use a command interface to read registers and then send a clear command after reading. The COG code should not be too hard to write for this for someone who writes PASM. It can also be done in C.
  • groggorygroggory Posts: 205
    edited 2012-06-21 12:56
    jazzed wrote: »
    The 8th COG will have to monitor what the other 7 produce in some mailbox locations. It is possible to pass a future CNT to all COGs at startup and make them synchronize their operation to it within a hub time for all (16 clock ticks). There are different ways snapshot and deliver the information. One way is for the COG code to look at phsa/b for changes in each COG and snap the time to a register then write that to the HUB RAM mailbox. The 8th COG could just poll the mail boxes or optionally use a command interface to read registers and then send a clear command after reading. The COG code should not be too hard to write for this for someone who writes PASM. It can also be done in C.

    Sounds like you're on to something...but I don't exactly follow you 100%...

    "The 8th COG will have to monitor what the other 7 produce in some mailbox locations."

    Do you mean that the 7 cogs should be running a simple program that loops and write's their registers to a global variable? Then Cog-8 can read those global variables. When it reads the global variables it should adjust timing appropriately such that the clock ticks that have passed (16 = full circle) are accounted for properly?

    Let me try to pseudo code out a way to do this...

    Global Memory:
    int CogCounts [7] = 0 -- count on each cog's register
    bool getCounts = false -- flag triggered by Cog-8 that notifies each cog that it wants to get the current state

    Each cog:
    ...counter running as appropriate

    Wait until getCounts=True Then
    CogCounts[cog#] = cogCounter

    wait until getCounts=false then
    end wait

    CogCounts[cog#] = 0
    repeat

    ....

    Does that sound about right? When you set getCounts=true in cog-8 that will notify all the cogs to snapshot their counter to CogCounts[cog#]. Once you've got the data you can reset the cogCounts[] back to 0 and set getCounts back to false.

    ...

    This could be easily written in spin, I just wonder if the precision will be good enough compared to writing it in assembly.
  • jmgjmg Posts: 15,183
    edited 2012-06-21 14:03
    groggory wrote: »
    ... When it reads the global variables it should adjust timing appropriately such that the clock ticks that have passed (16 = full circle) are accounted for properly?

    How fast are these external edges you are sampling ?

    You could also use a physical pin as a capture signal, either driven from a master cog, or just from a timer.
    ( also note there are 2 counters in each cog)
  • jazzedjazzed Posts: 11,803
    edited 2012-06-21 14:27
    groggory wrote: »
    Sounds like you're on to something...but I don't exactly follow you 100%...

    "The 8th COG will have to monitor what the other 7 produce in some mailbox locations."

    Do you mean that the 7 cogs should be running a simple program that loops and write's their registers to a global variable? Then Cog-8 can read those global variables. When it reads the global variables it should adjust timing appropriately such that the clock ticks that have passed (16 = full circle) are accounted for properly?

    You could do that.

    I meant that the 7 cogs can poll PHSA for an event count and save a time-stamp to HUB only on a change. That way the 8th cog only needs to read the data. If you have something else useful for the 7 cogs to do, they can still look for a change in the PHSA register somewhere in the program loop.
    groggory wrote: »
    This could be easily written in spin, I just wonder if the precision will be good enough compared to writing it in assembly.

    Yes, that's right, but the time stamp would have milli-seconds of error. The problem can occur in PASM, but the error window would be smaller if PASM is writing the time stamp.


    You could also use waitpne/waitpeq in separate SPIN cogs, but no events would mean no counts. That's easier to write.
  • groggorygroggory Posts: 205
    edited 2012-06-21 14:58
    jazzed wrote: »
    You could do that.

    I meant that the 7 cogs can poll PHSA for an event count and save a time-stamp to HUB only on a change. That way the 8th cog only needs to read the data. If you have something else useful for the 7 cogs to do, they can still look for a change in the PHSA register somewhere in the program loop.



    Yes, that's right, but the time stamp would have milli-seconds of error. The problem can occur in PASM, but the error window would be smaller if PASM is writing the time stamp.


    You could also use waitpne/waitpeq in separate SPIN cogs, but no events would mean no counts. That's easier to write.

    Ok, great. I think I'm on the right track. I'm going to do some more thinking on this, but I think I have some good inspiration now.

    Thank you!

    I'll post back when I figure out how to put it all together.
Sign In or Register to comment.