Shop Learn
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 }}


  • roglohrogloh Posts: 3,246


  • Thank you

  • JonnyMacJonnyMac Posts: 7,570
    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()
        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.

  • MagIO2MagIO2 Posts: 2,243

    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.

  • JonnyMacJonnyMac Posts: 7,570

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

    pub getct64() : lo, hi
                    getct     hi                            wc      ' get system counter
                    getct     lo
  • MagIO2MagIO2 Posts: 2,243


    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: 7,570
    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..."

  • AJLAJL Posts: 377

    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: 10,929
    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.