waitpne vs. pin monitor loop
toddbest79
Posts: 4
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.
vs.
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?
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
BTW, this test uses one less instruction and one less auxiliary variable:
-Phil
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
Post Edited (Phil Pilgrim (PhiPi)) : 3/10/2010 8:54:24 PM GMT
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
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
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
Thanks for your help
Regards,
Todd