Shop OBEX P1 Docs P2 Docs Learn Events
PASM waitpeq not working as expected — Parallax Forums

PASM waitpeq not working as expected

The code gates one pin of 500Hz oscillation with another pin (high/low).

The SPIN code works with `waitpeq(|<TRIG1, |<TRIG1, 0)`.

However the PASM code doesn't. T_PIN stays high, even though R_PIN changes.

Comment out `waitpeq R_PIN, R_PIN` makes T_PIN toggles at 500Hz.





CON
   
  _clkmode = xtal1 + pll16x                             ' Crystal and PLL settings.
  _xinfreq = 5_000_000                                  ' 5 MHz crystal (5 MHz x 16 = 80 MHz).

CON         
  TRIG1 = 20
  

PUB main
  cognew(@T1,0)
  
  dira[22]~~


  repeat                  
    waitpeq(|<TRIG1, |<TRIG1, 0)
    outa[22] := 0
    waitcnt(clkfreq/1000 + cnt)
    outa[22] := 1
    waitcnt(clkfreq/1000 + cnt)


DAT
        org
T1
        'SET AS OUPUT
        OR dira, T_PIN

        mov time, cnt
        add time, delay_t        


        
loop
        waitpeq R_PIN, R_PIN    
        or outa, T_PIN                
        waitcnt time, delay_t
        andn outa, T_PIN     
        waitcnt time, delay_t      
        jmp #loop


R_PIN long |< 20
T_PIN long |< 21 
delay_t long 1_000

time res 1


Comments

  • You need to put this:
            mov time, cnt
            add time, delay_t        
    

    after the or outa,T_Pin.

    -Phil
  • Ding-BattyDing-Batty Posts: 274
    edited 2018-05-26 14:24
    Your Spin loop is toggling pin 22 at 500 Hz, but your PASM code is toggling pin 21muich faster: 80MHz / 2000 = 40KHz

    The CNT increment in the Spin loop is 2 * 80MHz/1000 == 160K, but the CNT increment in PASM is only 2 * 1000 = 2K,
    Change delay_t to long 80000.
  • You need to put this:
            mov time, cnt
            add time, delay_t        
    

    after the or outa,T_Pin.

    -Phil

    Thanks Phil. I fell into the WAITCNT trap. You saved me there.
Sign In or Register to comment.