Shop OBEX P1 Docs P2 Docs Learn Events
P2 WAITCNT — Parallax Forums

P2 WAITCNT

Hello,

this command does not exist in P2.

How can I recreate this on the P2?

Comments

  • I believe this has been replaced with WAITX.

    Mike

  • pic18f2550pic18f2550 Posts: 392
    edited 2021-03-04 11:10

    If I read the description of "WAITX" correctly, you can stop the COG by n CLOCK pulses.

    I have to start a program loop, with different length, but always at the same time.

    This was no problem with WAITCNT because a value was simply added to the counter.

  • AribaAriba Posts: 2,682

    WAITCNT is now called WAITCT1..3 in PASM and you use it together with ADDCT1..3. So you can handle 3 different time periods.
    It's all described in the documentation (see chapter: Events)

    In Spin2 it's just WAITCT().

    Andy

  • Cluso99Cluso99 Posts: 18,069

    See the p2 tricks and traps reference thread for p2 replacement code

  • Thank you.

  • JonnyMacJonnyMac Posts: 8,924
    edited 2021-03-04 21:20

    As the waitct? instructions do not reload the timer, you have to use addct? first.

    pub blinker(pin, count, hitix, lotix) | t
    
      org
                    getct     t
    
    .loop           drvh      pin
                    addct1    t, hitix
                    waitct1
                    drvl      pin
                    addct1    t, lotix
                    waitct1
                    djnz      count, #.loop
      end
    
  • How does waitcnt behave when the time is up?

    The code is processed without interruption and the associated flag is cleared?

    In the example, I simply want to limit the repetition rate to a maximum value.
    Falling below this value is not a problem.

    CON
      _clkfreq = 20_000_000
    
    pub blinker(pin, hitix, lotix) | t
    
      org
                    jmp       #.go
    
    .loop
                    '' routine unbekannter länge
                    '' der zeitbedarf ist unter oder über hitix
                    waitct1
    .go             getct     t
                    addct1    t, hitix
                    drvh      pin
    
                    '' routine unbekannter länge
                    '' der zeitbedarf ist unter oder über lotix
                    waitct1
                    getct     t
                    addct1    t, lotix
                    drvl      pin
    
                    jmp      #.loop
      end
    
  • evanhevanh Posts: 15,187

    @pic18f2550 said:
    How does waitcnt behave when the time is up?

    The code is processed without interruption and the associated flag is cleared?

    Yes.

    In the example, I simply want to limit the repetition rate to a maximum value.
    Falling below this value is not a problem.

                    ...
                    waitct1
    .go             getct     t
                    addct1    t, hitix
                    ...
                    waitct1
                    getct     t
                    addct1    t, lotix
                    ...
    

    Correct use of recurring GETCT. It starts a fresh timeout each time.

  • pic18f2550pic18f2550 Posts: 392
    edited 2021-06-29 12:06

    Since the variable t is reloaded each time overflow occurs,
    the values hitix and lotix should be set to 2 less.

    Then everything should fit.

  • evanhevanh Posts: 15,187

    @pic18f2550 said:
    Since the variable t is reloaded each time overflow occurs,
    the values hitix and lotix should be set to 2 less.

    Then everything should fit.

    I wouldn't bother unless it costs nothing. It won't be consistent upon overruns.

  • I think JNCTx could replace WAITCTx if
    (a) absolute precision is not needed
    (b) waits must be interruptible.

    Replace

            waitct1
    

    with

    .loop       jnct1   #.loop
    

    Am I correct?

  • A background is the runtime monitoring of several program pieces.
    This should already be accurate.

Sign In or Register to comment.