Shop OBEX P1 Docs P2 Docs Learn Events
[FYI] waitpxx cog synchronisation — Parallax Forums

[FYI] waitpxx cog synchronisation

kuronekokuroneko Posts: 3,623
edited 2012-08-16 11:55 in Propeller 1
Disclaimer: It's not rocket science but given what people think is acceptable a few words of advice. The list below may not be complete but contains what's usually suggested in this forum and what I use in preference.
  • cogs waitpxx on a pin which is controlled e.g. by a master cog
  • cogs waitcnt for a specific system counter value
  • hub-window utilisation
My personal favourite is the last, cogs know who they are and can therefore figure out what their distance to each other is based on a given hub-window access. waitcnt is acceptable too but suffers from the requirement that cnt has to be agreed on and then communicated. So what's wrong with the first one? Nothing at all as long as you are aware that certain pin/cog assignments will give you anything but synchronisation (starting at 80MHz and probably higher).

Delay maps

What's a delay map? Well, it's simple. cog A sends out a signal (rising edge) to pin B. cog C will waitpxx on pin B looking for the rising edge. Both events are recorded with time-stamps for all valid cog pairings and all available pins. Ideally the delay is always the same. Unfortunately it isn't. I looked at a number of different ways of generating a rising edge and in the end it boils down to outa and phsx. The former simply sets a bit while the latter can use any known way of affecting a counter output.

I'll attach delay maps for the PPDB with a naked prop (no EEPROM) testing all pins excluding 30/31 and for my rev G demoboard with a limited pin map. The hard-wired (expected) delay is 3 cycles (dash), deviations are marked with # (4 cycles). Unused pins are marked with a dot.

What we find is that while the outa method is superior to phsx it is not perfect. Let's look at the sections where cog 0/1 is the edge generator.
[COLOR="green"]0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3[/COLOR]
T.R: [COLOR="green"]0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1[/COLOR]   outa
[COLOR="red"]0[/COLOR].[COLOR="blue"]1[/COLOR]: - - - - - - - - - - - - - - - - # # # # # # # - - # # # # # . .
[COLOR="red"]0[/COLOR].[COLOR="blue"]2[/COLOR]: - - - - - - - - - - - - - - - - # # # # # # # - - # # # # # . .
[COLOR="red"]0[/COLOR].[COLOR="blue"]3[/COLOR]: - - - - - - - - - - - - - - - - # # # # # # # - - # # # # # . .
[COLOR="red"]0[/COLOR].[COLOR="blue"]4[/COLOR]: - - - - - - - - - - - - - - - - # # # # # # # - - - # # # # . .
[COLOR="red"]0[/COLOR].[COLOR="blue"]5[/COLOR]: - - - - - - - - - - - - - - - - # # # # # # - - - - # # # # . .
[COLOR="red"]0[/COLOR].[COLOR="blue"]6[/COLOR]: - - - - - - - - - - - - - - - - # # # # # # - - - - # # # # . .
[COLOR="red"]0[/COLOR].[COLOR="blue"]7[/COLOR]: - - - - - - - - - - - - - - - - # # # # # - - - - - - # # # . .
[COLOR="red"]1[/COLOR].[COLOR="blue"]0[/COLOR]: - - - - - - - - - - - - - - - - # # # - - - - - - - - - - - . .
[COLOR="red"]1[/COLOR].[COLOR="blue"]2[/COLOR]: - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - . .
[COLOR="red"]1[/COLOR].[COLOR="blue"]3[/COLOR]: - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - . .
[COLOR="red"]1[/COLOR].[COLOR="blue"]4[/COLOR]: - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - . .
[COLOR="red"]1[/COLOR].[COLOR="blue"]5[/COLOR]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . .
[COLOR="red"]1[/COLOR].[COLOR="blue"]6[/COLOR]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . .
[COLOR="red"]1[/COLOR].[COLOR="blue"]7[/COLOR]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . .

So if we look at pin 25 it turns out that cogs 1..3 will get the signal one clock cycle later than cogs 4..7. Or rather their waitpxx h/w sees it slightly later. NG

For comparison the other end (cog 6/7):
[COLOR="red"]6[/COLOR].[COLOR="blue"]0[/COLOR]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . .
[COLOR="red"]6[/COLOR].[COLOR="blue"]1[/COLOR]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . .
[COLOR="red"]6[/COLOR].[COLOR="blue"]2[/COLOR]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . .
[COLOR="red"]6[/COLOR].[COLOR="blue"]3[/COLOR]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . .
[COLOR="red"]6[/COLOR].[COLOR="blue"]4[/COLOR]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . .
[COLOR="red"]6[/COLOR].[COLOR="blue"]5[/COLOR]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . .
[COLOR="red"]6[/COLOR].[COLOR="blue"]7[/COLOR]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . .
[COLOR="red"]7[/COLOR].[COLOR="blue"]0[/COLOR]: - - - - - - - - - - - - - # # # - - - - - - - - - - - - - - . .
[COLOR="red"]7[/COLOR].[COLOR="blue"]1[/COLOR]: - - - - - - - - - - - - - # # # - - - - - - - - - - - - - - . .
[COLOR="red"]7[/COLOR].[COLOR="blue"]2[/COLOR]: - - - - - - - - - - - - - # # # - - - - - - - - - - - - - - . .
[COLOR="red"]7[/COLOR].[COLOR="blue"]3[/COLOR]: - - - - - - - - - - - - # # # # - - - - - - - - - - - - - - . .
[COLOR="red"]7[/COLOR].[COLOR="blue"]4[/COLOR]: - - - - - - - - - - - - # # # # - - - - - - - - - - - - - - . .
[COLOR="red"]7[/COLOR].[COLOR="blue"]5[/COLOR]: - # - - - - - - - - - # # # # # - - - - - - - - - - - - - - . .
[COLOR="red"]7[/COLOR].[COLOR="blue"]6[/COLOR]: - # # - - - - - - - # # # # # # - - - - - - - - - - - - - - . .
T.R: [COLOR="green"]0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3[/COLOR]
     [COLOR="green"]0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1[/COLOR]

A few words for operating the test program. Results are written after the test to serial. The pins to be tested are simply defined in a 32bit vector called pins which is effectively your dira mask. In order to pick a test method (default is outa.) select either of the following:
CON
  pins = $0FFFF0FF                  ' demoboard
  
DAT
'   [COLOR="green"]movi    ctrb, #%0_00100_000[/COLOR]     '
'   [COLOR="green"]neg     phsb, #1[/COLOR]                '                       ** phsx

    [COLOR="darkorange"]or      outa, m_tx[/COLOR]              ' low high edge         ** outa

Be careful out there!

Comments

  • prof_brainoprof_braino Posts: 4,313
    edited 2010-12-04 17:29
    This is really interesting. How did you happen to run across this?

    Is this related to the "clean up" for audio in the Stereo-Duty object?

    http://forums.parallax.com/showthread.php?123396-New-Propeller-based-Product&highlight=audio

    It talks about "relationship between you IO pins for the DACs and the cog location on the die"

    Is due to physical distances being different for each cog?
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-04 17:50
    This is really interesting. How did you happen to run across this?

    Is this related to the "clean up" for audio in the Stereo-Duty object?
    Admittedly that issue played a part in it. However, primary driving force was my [post=784536]serial driver project[/post]. As for the Stereo-Duty object, I wish I could explain it properly. ATM I'm not so much concerned about noise but the jitter effect. Let's say you output $00010001. This means - after un/signing - the DUTY counter is fed with &80010000 which generates an audible signal of a few kHz. Funny thing is it is loudest on cog 7, slightly less so for cog 6 and hardly noticable for all other cogs. And this is independent of the output pin. The delay maps clearly show that cog 7 favours pin groups 2 and 3 or rather there is some kind of symmetry in all this (low cog IDs favour low pin groups and vice versa).

    So far I managed to simulate DUTY behaviour for $80010000 with an NCO (40MHz plus inversion of the output for 32767 cycles). What I get is my kHz noise loud and clear independent of cog ID (although slightly less so for cog 7, about 80% I'd say). But this suggests there is something funny going on with the DUTY carry output. But that's something for a rainy day.
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-12-04 19:10
    Wow - nice detective work kuroneko :)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-04 19:39
    Kuroneko,

    I hope you're in communication with Chip on these matters. I can't help thinking that these anomalies will only be amplified in the Prop 2 if the same general circuitry is used.

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-04 19:52
    I hope you're in communication with Chip on these matters. I can't help thinking that these anomalies will only be amplified in the Prop 2 if the same general circuitry is used.

    Not regarding this specific issue (yet), but I have a pending clarification request with Jeff (which in the end depends on Chip) regarding waitvid's [thread=126874]blind spot[/thread]. But now that you mention it I'll send it down the pipe as well.
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-12 05:47
    An update to the delay mapper is now available (first post, delay.map.timeout). It now allows for easy selection of three edge generation modes:
    CON
      #0, outa_, nco__, duty_       ' test modes
    
      M = duty_                     ' default
    

    The latter was newly introduced because DUTY cycles have the nasty property of occasionally being invisible. Meaning the mapping wouldn't complete. This has now been resolved by introducing a timeout while waiting for the result. Test cancellation due to timeout is indicated by '?' (expected timing '-', extra cycle '#'). Example shows DUTY test mode on my primary demoboard (TX: cogs 1..3).
    [COLOR="green"]0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3[/COLOR]
    T.R: [COLOR="green"]0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1[/COLOR]   phsx.duty
    [COLOR="red"]1[/COLOR].[COLOR="blue"]0[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]# [/COLOR]# # # # # # # # # . . . .
    [COLOR="red"]1[/COLOR].[COLOR="blue"]2[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]# [/COLOR]# # # # ? # # # # . . . .
    [COLOR="red"]1[/COLOR].[COLOR="blue"]3[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]# [/COLOR]# # # # # # # # # . . . .
    [COLOR="red"]1[/COLOR].[COLOR="blue"]4[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]# [/COLOR]# # # # ? # # # # . . . .
    [COLOR="red"]1[/COLOR].[COLOR="blue"]5[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]# [/COLOR]# # # # # # # # # . . . .
    [COLOR="red"]1[/COLOR].[COLOR="blue"]6[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]# [/COLOR]# # # # ? # # # # . . . .
    [COLOR="red"]1[/COLOR].[COLOR="blue"]7[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]# [/COLOR]# # # # ? # # # # . . . .
    [COLOR="red"]2[/COLOR].[COLOR="blue"]0[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]# [/COLOR]? ? ? ? ? ? ? ? ? . . . .
    [COLOR="red"]2[/COLOR].[COLOR="blue"]1[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]? [/COLOR]? ? ? ? ? ? ? ? ? . . . .
    [COLOR="red"]2[/COLOR].[COLOR="blue"]3[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]# [/COLOR]? ? ? ? ? ? ? ? ? . . . .
    [COLOR="red"]2[/COLOR].[COLOR="blue"]4[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]? [/COLOR]? ? ? ? ? ? ? ? ? . . . .
    [COLOR="red"]2[/COLOR].[COLOR="blue"]5[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]? [/COLOR]? ? ? ? ? ? ? ? ? . . . .
    [COLOR="red"]2[/COLOR].[COLOR="blue"]6[/COLOR]: - - - - - - - - . . . . - - - - # # [COLOR="darkorange"]? [/COLOR]? ? ? ? ? ? ? ? ? . . . .
    [COLOR="red"]2[/COLOR].[COLOR="blue"]7[/COLOR]: - - - - - - - - . . . . - - - - ? # [COLOR="darkorange"]? [/COLOR]? ? ? ? ? ? ? ? ? . . . .
    [COLOR="red"]3[/COLOR].[COLOR="blue"]0[/COLOR]: - - - - - - - - . . . . - - - - ? ? [COLOR="darkorange"]? [/COLOR]? ? ? - - - - ? ? . . . .
    [COLOR="red"]3[/COLOR].[COLOR="blue"]1[/COLOR]: - - - - - - - - . . . . - - - - ? ? [COLOR="darkorange"]? [/COLOR]? ? ? - - - - ? ? . . . .
    [COLOR="red"]3[/COLOR].[COLOR="blue"]2[/COLOR]: [COLOR="darkorange"]- - - - - - - - . . . . - - - - ? ?[/COLOR] [COLOR="blue"]? [/COLOR]? ? ? - - - - - ? . . . .
    [COLOR="red"]3[/COLOR].[COLOR="blue"]4[/COLOR]: - - - - - - - - . . . . - - - - ? ? ? ? ? - - - - - - ? . . . .
    [COLOR="red"]3[/COLOR].[COLOR="blue"]5[/COLOR]: - - - - - - - - . . . . - - - - ? ? ? ? ? - - - - - - ? . . . .
    [COLOR="red"]3[/COLOR].[COLOR="blue"]6[/COLOR]: - - - - - - - - . . . . - - - - ? ? ? ? ? ? - - - - ? ? . . . .
    [COLOR="red"]3[/COLOR].[COLOR="blue"]7[/COLOR]: - - - - - - - - . . . . - - - - ? ? ? ? ? - - - - - - ? . . . .
    
    Which basically means that signalling from cog 3 to cog 2 via pin 18 using DUTY is not happening (@80MHz).
  • WossnameWossname Posts: 174
    edited 2012-03-08 05:22
    Now that's fascinating stuff. Great work Kuroneko.


    I have some general questions about this phenomenon that I'd like to ask to anyone who might have insight into it...

    Q1 - Are these timing anomalies deterministic for a given chip (will the same chip always give an identical set of characteristics)?
    Q2 - Do all propeller chips give the same exact set of characteristics?
    Q3 - Do the different packages (D40, M44 and Q44) all have the same results?
    Q4 - Presumably whatever is connected to the pin on the circuit board will have an effect on the rise and fall time of the pin, could that account for (or contribute to) these anomalies?
    Q5 - What effect will cross talk between adjacent IO pins have on this inter-cog communication method at higher frequencies? (I've often noticed alarmingly high coupling on adjacent pins on the D40).
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-16 08:36
    Kuroneko,

    I've recently found that DUTY output can also be invisible to the cog that's producing it! I used that "feature" to advantage in the Ping))) workaround for the S2 by biasing the I/O pin to a lower voltage than the usual Vdd pullup. Even though the pin is thereby made into an output, ina is still sensitive to external influences. And, while waitpeq does not respond to the DUTY pulses, it does respond when combined with a momentary external low. It's weird. After writing the code, I thought, "How does this even work?"

    -Phil
  • HumanoidoHumanoido Posts: 5,770
    edited 2012-08-16 11:55
    kuroneko, congratulations on this remarkable spatial representation of Cog delay mapping.
  • Here is the chart from http://forums.parallax.com/discussion/comment/976476/#Comment_976476 reformatted.

    timeout is indicated by '?'
    expected timing '-'
    extra cycle '#'
         0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
    T.R: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1   phsx.duty
    1.0: - - - - - - - - . . . . - - - - # # # # # # # # # # # # . . . .
    1.2: - - - - - - - - . . . . - - - - # # # # # # # ? # # # # . . . .
    1.3: - - - - - - - - . . . . - - - - # # # # # # # # # # # # . . . .
    1.4: - - - - - - - - . . . . - - - - # # # # # # # ? # # # # . . . .
    1.5: - - - - - - - - . . . . - - - - # # # # # # # # # # # # . . . .
    1.6: - - - - - - - - . . . . - - - - # # # # # # # ? # # # # . . . .
    1.7: - - - - - - - - . . . . - - - - # # # # # # # ? # # # # . . . .
    2.0: - - - - - - - - . . . . - - - - # # # ? ? ? ? ? ? ? ? ? . . . .
    2.1: - - - - - - - - . . . . - - - - # # ? ? ? ? ? ? ? ? ? ? . . . .
    2.3: - - - - - - - - . . . . - - - - # # # ? ? ? ? ? ? ? ? ? . . . .
    2.4: - - - - - - - - . . . . - - - - # # ? ? ? ? ? ? ? ? ? ? . . . .
    2.5: - - - - - - - - . . . . - - - - # # ? ? ? ? ? ? ? ? ? ? . . . .
    2.6: - - - - - - - - . . . . - - - - # # ? ? ? ? ? ? ? ? ? ? . . . .
    2.7: - - - - - - - - . . . . - - - - ? # ? ? ? ? ? ? ? ? ? ? . . . .
    3.0: - - - - - - - - . . . . - - - - ? ? ? ? ? ? - - - - ? ? . . . .
    3.1: - - - - - - - - . . . . - - - - ? ? ? ? ? ? - - - - ? ? . . . .
    3.2: - - - - - - - - . . . . - - - - ? ? ? ? ? ? - - - - - ? . . . .
    3.4: - - - - - - - - . . . . - - - - ? ? ? ? ? - - - - - - ? . . . .
    3.5: - - - - - - - - . . . . - - - - ? ? ? ? ? - - - - - - ? . . . .
    3.6: - - - - - - - - . . . . - - - - ? ? ? ? ? ? - - - - ? ? . . . .
    3.7: - - - - - - - - . . . . - - - - ? ? ? ? ? - - - - - - ? . . . .
    
Sign In or Register to comment.