Shop OBEX P1 Docs P2 Docs Learn Events
[invalid][puzzle] Nine Cycles of Hell — Parallax Forums

[invalid][puzzle] Nine Cycles of Hell

kuronekokuroneko Posts: 3,623
edited 2011-06-24 17:22 in Propeller 1
Disclaimer: This is more of an anti challenge as it may be impossible to solve, i.e. the result may differ from the set target.

The datasheet notes a 7..22 cycle timing for hub ops. A hub window being 16 cycles results in a nine cycle window before the next hub op can be issued (or rather is processed, 16 - 7 = 9). So let's not waste those nine cycles and fill them with a 4 cycle insn and a 5+ cycle insn of your choice, the latter set to minimum execution time.

With all the measurement going on it seems that everyone is happy with capturing cnt before and after, take the difference and adjust for overhead, e.g.
neg     mark, cnt
...                 ' instruction(s) to be measured
add     mark, cnt
sub     mark, #4
What I want is proof that there are nine cycles to spare. Basically, the sequence
neg     mark, cnt
[COLOR="Red"]cogid   cnt         ' 7[/COLOR]
...                 ' 9 cycle consumer
add     mark, cnt
sub     mark, #4

should clock in with 16 consumed cycles. It's part of the challenge to make sure that the cogid is sync'd to the hub window (and reading mark is aligned accordingly, i.e. hub window - 4).

Comments

  • Andrey DemenevAndrey Demenev Posts: 377
    edited 2010-09-06 01:33
    Just a side note for those trying to solve this - WAITPxx minimum execution time is 6 cycles, not 5
    entry
            mov     DIRA, #1
            neg     tmp, CNT
            waitpne DIRA, DIRA
            add     tmp, cnt
            sub     tmp, #4
            wrlong  tmp, PAR
            cogid   tmp
            cogstop tmp
    
    tmp     res   1
    
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-09-06 05:30
    As I understand it, there are no 5 clock instructions. The ones noted as 5 are in fact 6 minimum.

    AFAIK the only way to do this is to delay 2 hub cycles and use the waitcnt to do the timing. I am busy with other thinks otherwise I would try.
  • kuronekokuroneko Posts: 3,623
    edited 2010-09-17 07:28
    As of today Parallax have officially (enough for me) acknowledged that hub ops take 8..23 cycles therefore invalidating this puzzle (which kind of was the idea from the start). So you can stop pulling your hair out finding that elusive 9th cycle.

    The timing will be updated in the next revision of the documention along with the actual values for waitpxx/waitcnt and waitvid (6+/4+).
  • Heater.Heater. Posts: 21,230
    edited 2010-09-17 07:41
    kuroneko,
    As of today Parallax have officially (enough for me) acknowledged that hub ops take 8..23

    Blimey, no wonder Zog is so slow:)
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-09-17 08:45
    I do think I understand where the confusion came from.

    If you run this code and look at a scope...
    CON
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
    PUB Pasm
        cognew(@Entry,0)        
    DAT
    Entry
            mov   dira,     #1
    Loop    mov   outa,     #1
            nop
            mov   outa,     #0
            jmp   #Loop
    

    ... the HIGH time will be 100ns. However if you run this code ...
    CON
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
    PUB Pasm
        cognew(@Entry,0)        
    DAT
    Entry
            mov   dira,     #1
    Loop    mov   outa,     #1
            waitpeq         dira,dira
            mov   outa,     #0
            jmp   #Loop
    

    ... the HIGH time will be 125ns and I think (<-THAT) is where the confusion came from and how it was miscalculated and made it's way into the documentation. Intuitively if you think 100ns for a command that you know to take 4 clocks, and then look at a command that indicates 125ns, then you just assume there is a 5th clock.

    What your not considering is the processing overhead time required for making the pin HIGH, and then LOW again. Look at this code ...
    CON
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
    PUB Pasm
        cognew(@Entry,0)        
    DAT
    Entry
            mov   dira,     #1
    Loop    mov   outa,     #1
            mov   outa,     #0
            jmp   #Loop
    

    ... the HIGH time is 50ns. So in the above scenario you should be comparing 50ns and 75ns by subtracting 50ns from your original readings.

    50ns = 100ns - 50ns
    75ns = 125ns - 50ns


    ... So if 50ns is equal to 4 clock cycles (12.5ns * 4 = 50ns) then 75ns is equal to 6 clock cycles (12.5ns * 6 = 75ns)
  • mparkmpark Posts: 1,305
    edited 2010-09-17 08:46
    kuroneko wrote: »
    As of today Parallax have officially (enough for me) acknowledged that hub ops take 8..23 cycles

    Citation needed?
    kuroneko wrote: »
    The timing will be updated in the next revision of the documention along with the actual values for waitpxx/waitcnt and waitvid (6+/4+).

    That's great! Accurate documentation is a must. Thank you for being on the case.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-09-17 10:14
    I'm not sure why an "official" word on hub timings is even needed, when the empirical evidence alone is sufficient to nail down the figures conclusively:
    CON
    
       _clkmode       = xtal1 + pll16x
       _xinfreq       = 5_000_000
    
    OBJ
    
      sio   : "FullDuplexSerial"
    
    VAR
    
      byte  time
    
    PUB  Start
    
      sio.start(341, 30, 0, 9600)
      cognew(@timer, @time)
      repeat
        if (time)
          sio.dec(time)
          sio.tx(" ")
          time~
    
    DAT
    
    timer         mov       count,#24
    
    :tloop        neg       acc,cnt
                  wrbyte    dtime,par
                  add       acc,cnt
                  sub       acc,#4
                  mov       dtime,acc
                  mov       acc,cnt
                  add       acc,delay
                  waitcnt   acc,#0
                  add       delay,#1
                  djnz      count,#:tloop
                  jmp       #$
    
    dtime         long      0
    delay         long      80_000_000/10
    
    acc           res       1
    count         res       1
    
    and the output:
    20 19 18 17 16 15 14 13 12 11 10 9 8 23 22 21 20 19 18 17 16 15 14
    

    -Phil
  • mparkmpark Posts: 1,305
    edited 2010-09-17 12:15
    I'm not sure why an "official" word on hub timings is even needed, when the empirical evidence alone is sufficient to nail down the figures conclusively:

    Seriously? Don't you think the docs should match reality?

    Not everyone has the PASM chops to figure it out for themselves. I for one don't understand what your program does. Care to elucidate, please?
  • tonyp12tonyp12 Posts: 1,951
    edited 2010-09-17 12:54
    timer         mov       count,#24    ' Run this 24 times
    
    :tloop        neg       acc,cnt      ' Get current counter value, but make it negative num.
                  wrbyte    dtime,par    ' dtime=0 first time, below we will calc it.
                                         ' Write the dtime value to the hub address represented in par
                                         ' spin have already reserved it's hub address with '@time'
                  add       acc,cnt      ' How long did the above hub-op take?
                  sub       acc,#4       ' Subtract 4 cycles for overhead
                  mov       dtime,acc    ' Move the new answer to dtime.
    
                  mov       acc,cnt    ' reset acc with current counter value. 
                  add       acc,delay  ' add the delay we want 
                  waitcnt   acc,#0     ' Wait
                  add       delay,#1   ' Next time wait one more cycle and see
                                        if our hub window will be at a better or worse position.
                  djnz      count,#:tloop ' is 24 loops up yet?
                  jmp       #$            ' jmp forever to this same line.
    
    dtime         long      0
    delay         long      80_000_000/10
    
    acc           res       1
    count         res       1
    
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-09-17 13:31
    Hey Michael,

    I think you misunderstood my comment. (In fact, I hadn't read your comment when I posted my code, else I might have phrased mine differently.) Of course, accurate documentation is a must. I was only responding to Kuroneko's statement, "As of today Parallax have officially (enough for me) acknowledged that hub ops take 8..23 cycles..." Some might interpret this to imply that it's not real until Parallax verifies that it's real. What I was trying to get across is this: Always trust your own experience before you trust anything "official".

    tonyp12,

    Thanks for commenting my code for me. In my haste to post, I left out that important detail. My apologies to the forum.

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2010-09-17 17:03
    I'm not sure why an "official" word on hub timings is even needed, when the empirical evidence alone is sufficient to nail down the figures conclusively.

    Personally I don't need any official word. But mismatching documentation somehow gets up my nose especially when it's this easy to fix. As for evidence, why would a newcomer to PASM even question the data sheet? Some of us did for their own reasons and as I'm usually a nice person I don't see why other people should find out the hard way (as it's just an irritating distraction).

    Don't read too much into it, it wasn't meant in the way you suggested it could be interpreted :) I could have simply said they'll update the documention.

    @mpark: re: citation, ATM I'm sorting out some other issues with Jeff Martin, he confirmed this in an email and I'm free to spill the beans. That has to be enough for now.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-09-17 18:40
    I guess the reason it's taken 4 1/2 years (!) for the right figures to appear in the documentation is that it's taken almost that long for the difference they represent to be important to anyone. And it's still not a difference that will matter much to most PASM programmers. Now, if the true figures had been 9..24, most of us would have recognized the discrepancy much sooner!

    -Phil
  • kuronekokuroneko Posts: 3,623
    edited 2011-06-23 16:48
    The documentation has now been updated (datasheet rev 1.4).
  • BradCBradC Posts: 2,601
    edited 2011-06-24 06:44
    kuroneko wrote: »
    @mpark: re: citation, ATM I'm sorting out some other issues with Jeff Martin, he confirmed this in an email and I'm free to spill the beans. That has to be enough for now.

    Hell, I'm impressed you even got a response. Well done!
  • SapiehaSapieha Posts: 2,964
    edited 2011-06-24 09:19
    Hi All.

    I have looked on this datasheet and still see ERRORS.

    On page 5 in Schematics I Don't see any decoupling capacitor. In my opinion it is why all NEW user's on PEKit build theirs experiments on breadboard Without that capacitors and in some cases have problems.



    kuroneko wrote: »
    The documentation has now been updated (datasheet rev 1.4).
  • kuronekokuroneko Posts: 3,623
    edited 2011-06-24 16:48
    Sapieha wrote: »
    I have looked on this datasheet and still see ERRORS.
    If we are being picky then yes I'd say the latest release of updates was premature. There is still so much wrong in the manual it's not funny. One of my favourites (wrlong wz):
    The Z flag is always cleared (0) since the main memory address (bits 13:2) is always on a long boundary.
  • SapiehaSapieha Posts: 2,964
    edited 2011-06-24 17:22
    Hi kuroneko.

    Yes - we need BE

    That are good to all - Both Parallax and us to have manual that are correct.

    kuroneko wrote: »
    If we are being picky then yes I'd say the latest release of updates was premature. There is still so much wrong in the manual it's not funny. One of my favourites (wrlong wz):
Sign In or Register to comment.