Shop OBEX P1 Docs P2 Docs Learn Events
waitpne vs. pin monitor loop — Parallax Forums

waitpne vs. pin monitor loop

toddbest79toddbest79 Posts: 4
edited 2010-03-10 22:48 in Propeller 1
I need to detect a transition of P0 from high to low. waitpne works fine, but I need to do some other
things while monitoring the pin, so I implemented version 2.
  ' Version 1
  waitpne state,mask                     ' wait while pin <> state (i.e. P0 = One)
  .
  .
state long 0
mask long 1



vs.
  ' Version 2
[img]http://forums.parallax.com/images/smilies/tongue.gif[/img]hi  mov r1,ina                           ' loop while pin P0 = One
        and r1,mask
        tjnz r1,#[img]http://forums.parallax.com/images/smilies/tongue.gif[/img]hi
  .
  .
mask long 1
r1 res 1




After a lot of debug work, I found that the tnjz was the issue. When it is replaced with tjz, it works!
What am I missing?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-10 20:12
    'Not sure why your original Version 2 doesn't work. What does the signal that you're monitoring look like? It's almost always better to check first that the pin is high before going into a "looking for low" loop. Otherwise, if it's still low from a prior event, you will get a false trigger.

    BTW, this test uses one less instruction and one less auxiliary variable:

    hi      test mask,ina wz
      if_nz jmp  #hi
    
    
    


    -Phil
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-03-10 20:24
    pin = 0
    mask = 1

    pin & mask = 0

    tjnz will not jump as the result is 0, but it jumps if result is Not Zero.

    But you want it to jump and wait until pin is 1, so tjz is the right one, as your debug prooved.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-10 20:47
    No, he wanted to wait for the pin to go from high to low, so tjnz would be the right choice. But detecting an edge requires more than a simple level test. Rereading his post, however, indicates some confusion about waitpne, as it's a wait until, not a wait while.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 3/10/2010 8:54:24 PM GMT
  • toddbest79toddbest79 Posts: 4
    edited 2010-03-10 21:07
    More Information:

    Signal starts in a high state, goes low for some amount of time, then returns high (
    \_____/
    ).
    I am using a counter in NEG mode to measure the low time.
    The process is as follows:
    1) Reset phsx
    2) Monitor for high to low: waitpne state,mask, where state is 0, mask is 1 (P0).
    3) Monitor for low to high: waitpeq state,mask, where state is 0, mask is 1 (P0).
    4) Record phsx.

    All works, I was just trying to replace #2 with the above described loop.
    Phil, your example works, except the if_nz needs to be if_z (still seems backwards).
    Regards to all
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-10 21:27
    I think you've misunderstood WAITPNE and WAITPEQ. To wait for a low state using WAITPNE, state and mask both have to equal one. You're waiting for them not to be equal, not waiting while they're not equal. Same applies to WAITPEQ: you're waiting for them to become equal.

    Why not do this:

    1. Program CTRA for NEG and PHSB for POS EDGE. FRQA,B := 1.
    2. Clear PHSA and PHSB.
    3. Wait for PHSB to be non-zero.
    4. Read PHSA to get the width.
    5. Go back to #2.

    -Phil
  • toddbest79toddbest79 Posts: 4
    edited 2010-03-10 22:01
    Hey Phil,
    Like your idea because if fits into a timeout scheme.

    Would still like to understand something though:
    Doesn't step #2, waitpne "0","1" wait while P0 is not equal to logic 0 (i.e. pin is high) and step #3, waitpeq "0","1" wait while P0 is equal to logic 0?

    -Todd
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-10 22:11
    toddbest79 said...
    Doesn't step #2, waitpne "0","1" wait while P0 is not equal to logic 0 (i.e. pin is high) and step #3, waitpeq "0","1" wait while P0 is equal to logic 0?
    No. The WAITPxx instructions are "wait until the condition is true", not "wait while the condition is true".

    -Phil
  • toddbest79toddbest79 Posts: 4
    edited 2010-03-10 22:48
    Ha! Funny thing about that until vs. while - Got it! (Read the manual hey!)

    Thanks for your help
    Regards,
    Todd
Sign In or Register to comment.