Shop OBEX P1 Docs P2 Docs Learn Events
P2 SPIN read CNT — Parallax Forums

P2 SPIN read CNT

How can I read out the cnt?
In PASM this is clear to me, but to spin I find nothing in the documentation.

sync := cnt {{ Alle COGs Starten }}

Comments

  • GETCT()

  • Thank you

  • JonnyMacJonnyMac Posts: 8,918
    edited 2021-04-08 15:15

    As Roger pointed out, retrieving the cnt register in Spin2 is different. Likewise, waiting for a specific count is, too.

      t := getct()
      repeat
        pintoggle(LED)
        waitct(t += (100 * MS_001))
    

    You can find the changes and new features in the timing section of the built-in functions part of the doc.

  • I wonder if it would be possible to return the low long AND the high long. In PASM2 it is possible to get the full 64 bit counter value.

    Now that we have multiple return values, it should be possible to do
    highct, lowct := getct()

    ... only has to be build into the SPIN2 interpreter I guess.

  • For the time being, you could inline it. I did this when getms() disappeared.

    pub getct64() : lo, hi
    
      org
                    getct     hi                            wc      ' get system counter
                    getct     lo
      end
    
  • @JonnyMac

    Hmmm ... looks like a solution :) ... or THE solution .. thanks.

    Because of that it is probably not worth to get into trouble with usage of
    waitct( getct() + x )

    Well .. well .. sometimes tomatoes are, where they should not be :o)
    ( Is it a valid phrase in english? We say "having tomatoes on the eyes" in case you miss to see the obvious )

  • JonnyMacJonnyMac Posts: 8,918
    edited 2021-04-08 22:11

    I have no great command of English, but we don't generally use tomato as a verb -- we'd usually say, "If some throws a tomato at me..."

  • A common English phrase is 'can't see the forest for the trees' for when you get caught up in the details, so you don't see the bigger picture.

  • The simple reading of the 32bit values brings a lot of errors.
    Because every 32bit overflow inevitably brings a new value in the Hi part.

    With 256Mhz this would happen every 16 seconds.
    With the Lo query, would have to be buffered for the next Hi query.

  • evanhevanh Posts: 15,171
    edited 2021-04-09 13:50

    @pic18f2550 said:
    ...
    With the Lo query, would have to be buffered for the next Hi query.

    All sorted with Jon's getct64() above. The paired instructions return an "atomic" snapshot of the 64-bit counter.

Sign In or Register to comment.