Shop OBEX P1 Docs P2 Docs Learn Events
Accessing the P2 system counter in Spin? — Parallax Forums

Accessing the P2 system counter in Spin?

Martin HebelMartin Hebel Posts: 1,239
edited 2023-09-06 04:34 in PASM2/Spin2 (P2)

Hi All,
Long time no play with the propeller chips.

How can I access the system counter via spin? I see an example using cnt, but when I compile it says it needs to be defined?

https://www.parallax.com/propeller/qna-mobile/Advanced/Content/CodeTeqTopics/CodeExeTime.htm

Thanks for the easy help. It's been a long night coming up to partial speed again with it after a prolonged break, where once I was a tester/early developer for the original Propeller, now I've forgotten nearly everything!

-Martin

Comments

  • @"Martin Hebel" said:
    Hi All,
    Long time no play with the propeller chips.

    How can I access the system counter via spin? I see an example using cnt, but when I compile it says it needs to be defined?

    https://www.parallax.com/propeller/qna-mobile/Advanced/Content/CodeTeqTopics/CodeExeTime.htm

    Thanks for the easy help. It's been a long night coming up to partial speed again with it after a prolonged break, where once I was a tester/early developer for the original Propeller, now I've forgotten nearly everything!

    -Martin

    On the P2 use getct(), for example create a variable called Count and do the following:

    Count := getct()

  • Thanks! Very Java-esq.

  • JonnyMacJonnyMac Posts: 8,957
    edited 2023-09-06 16:00

    Welcome back, Martin. There is a lot to like with the P2, and Spin2 is very nice. If you don't need system tick resolution, you can get the current milliseconds since reboot with

      t0 := getms()
    

    Or, if you want to go the other way, you can use P2's inline assembly feature to get all 64 bits of the system counter (returned as two longs)

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


    I've attached a Spin2 template that you might find useful as you come back up to speed.

  • Thanks Jon,
    I've gotten the new fullduplexserial going, but I will say it threw me an error on a variable called field. Apparently that's a keyword now? So I changed it something else and it worked fine.

    -Martin

  • JonnyMacJonnyMac Posts: 8,957
    edited 2023-09-06 19:23

    Yeah, that's happened twice: Chip updated the compiler with new keywords that trampled on method or variable names in jm_fullduplexserial. My latest is in that template archive (it compiles fine with Propeller Tool 2.9.3). The upside of all of this is that, unlike the P1 which had the interpreter frozen in silicon, Spin2 includes the interpreter code in the download which means it can be -- and has been -- updated.

    Once we have ObEx restored, I can keep my code updated online.

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2023-09-07 21:39

    Thanks for the great libraries Jon, using the P2 to drive my MakerPlot-J software to display a 1KHz sine wave.

  • Neat; I'm glad I could lend a hand.

Sign In or Register to comment.