Shop OBEX P1 Docs P2 Docs Learn Events
How do I syncronize two or more Cog´s — Parallax Forums

How do I syncronize two or more Cog´s

ciphernetciphernet Posts: 24
edited 2007-06-11 01:37 in Propeller 1
I have the need for synchronizing more than two Cog´s, I use for PWM.

Is there any "easy" (hopefully) way to do this?

Set a flag or...?

Anybody got a clever solution to this challenge.. ???

Thanks in advance...

Comments

  • mirrormirror Posts: 322
    edited 2007-06-08 05:33
    CNT is a global variable that is accessible by all cogs. It holds the system counter. That sounds perfect for synchronisation, to me.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    It's not all that hard to count the number of grains of sand on the beach. The hardest part is making a start - after that it just takes time.·· Mirror - 15 May 2007
  • StefanL38StefanL38 Posts: 2,292
    edited 2007-06-08 07:52
    one idea that i have is to use one timebaseloop and countervariables

    and then use COG-RAM countervariables to switch the logic level of the PWM-PINs

    basic principle

    increment a central countervariable by every loop
    compare value of central countervariable with another variable containing a value for the on/offtime of the PWM-signal
    if it matches change logical-level

    now it depends on the frequencies that you nedd
    for lower frequencies it might be possible in spin
    for higher frequencies you will need assembler

    is it nescessary to synchonize up every nanosecond ?

    write something very CONCRETE about your application

    greetings

    Stefan
  • ciphernetciphernet Posts: 24
    edited 2007-06-08 09:37
    Thanks for the replies.

    The thing is that I need to control a RGB backlight for a LCD display and if the timing is off on one or more of the RGB LED chains, there will be visual flicker and also the background color can change, because of the different resets, if the three PWM´s are not exactly timed.

    I thought about the idea regarding using·the global counter, but that will not keep the three channels synchronized in itself, since all three cog´s can not sync up to a common timing reference, because the propeller does not have a Interrupt like the SX chips that I use for other projects.

    I need some sort of "global" reset of PWM ASM code running·in the three Cog´s.

    Since the Propeller does not allow all three Cog´s to read a global flag at the same time, I have a bit of a problem.

    What if I set a pin as an output and run a Cog that keep track of the global counter and then set the pin high at some pre-determined point (right after maximum PWM time) and then let the three PWM cog´s detect that state-change...?? Would that be a good idea?? Afterall all three PWM cog´s can read the port at the same time...

    Am I on the right track?


    Jan
  • ciphernetciphernet Posts: 24
    edited 2007-06-08 09:45
    I just thought of a more simplified solution... comments please :-)

    I could of course also use one "primary" PWM Cog that could set a port pin high after each cycle and then two·"secondary" PWM Cog´s that are timing-slaved to the "primary" Cog.

    The two·"secondary" Cog´s·simply wait for a state-change after each PWM cycle and then I could save one Cog for other purposes.

    Does this sound okey??

    Seems pretty straight-forward but is it 100% sure that two or more Cog´s can access·the same·port pin at the same time without any problems or glitches?

    Jan
  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-06-08 10:00
    According the the Propeller manual, Pg 22, both the I/O pins AND the system counter are common resources that may be accessed at any time, and don't have to wait for the hub round robin. So I'd expect you to get the same result either way. But the CNT method needs no external wiring.
  • AnubisbotAnubisbot Posts: 112
    edited 2007-06-08 12:54
    Hi, how manny RGB led you want to control.

    I use the PCA9531 for driving the rgb leds.

    Here is a photo of my light board.

    I use a cog for 8 pwm lines for switching spotlights from 0 - 100 % and i use 2X PCA9531 for my rgb mix.

    If you hoock up two of those to the same address they a 100% syncrone.

    Anubisbot
    1280 x 960 - 518K
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-06-08 16:10
    ciphernet said...
    I thought about the idea regarding using·the global counter, but that will not keep the three channels synchronized in itself, since all three cog´s can not sync up to a common timing reference, because the propeller does not have a Interrupt like the SX chips that I use for other projects.
    This is faulty logic, because the Propeller does not have the same facilities you are accustomed to with other microcontrollers doesnt mean it's impossible to achieve.·The 1600x1200 video driver synchronizes 6 cogs precisely once at the beginning of execution and they remain synchronized for as long as power is applied to the Propeller, thats the power of true deterministic processing and is not possible in microcontrollers that use any interrupts besides RTC. You just have to think outside the box you are ordinarily accustomed to thinking in.

    The easiest form·of syncronization is·to choose some CNT value·that will occur in the near future but far enough out that you know all cogs will be able to get to the "starting block" in time. Each performs a WAITCNT on that value, and when that value occurs all cogs that are in a WAITCNT start executing thier following instructions in perfect synchronization, and if you·do time-symmetric programming they will remain in synchronization for as long as they run.·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 6/8/2007 4:15:26 PM GMT
  • IbsenIbsen Posts: 68
    edited 2007-06-08 22:17
    How do you handle CNT roll over in code ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    *.*

    Ibsen

    " It's nice to be important, but
    ·· more important to be nice... "
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-06-08 22:26
    Take the current value and add your "reasonable time difference for everyone to get ready". Since it's 32 bit value and 32 bit arithmatic, it is handled automatically.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • ciphernetciphernet Posts: 24
    edited 2007-06-09 13:00
    Hi Paul,

    Thanks very much for your reply. That´s what I needed. Great!
  • ciphernetciphernet Posts: 24
    edited 2007-06-09 13:01
    Anubisbot, Thanks also. You have a great project there smile.gif
  • AnubisbotAnubisbot Posts: 112
    edited 2007-06-09 13:54
    Thank you ciphernet,
    what is it where you are working on..



    scool.gif
  • ciphernetciphernet Posts: 24
    edited 2007-06-11 01:37
    Anubisbot,

    LCD backlights (high-brightness for custom applications) with tunable color temperature control
Sign In or Register to comment.