wait pne/peq and the Z flag
The propeller quick reference gives the Z flag as result = 0.
What is the result?
For example, I'm waiting on 2 pins to be in a certain state.. let's say..
pinstate = 0100
pinmask = 0110
If I do waitpeq pinstate, pinmask wz
What happens to the Z flag? I would expect it to be 0 as pinstate & pinmask <> 0
If I'm using waitpne pinstate, pinmask wz
If the pins are all clear, I'd expect the Z flag to be set, as pinstate & pinmask == 0.
I'm not seeing this behaviour however. I have to do an additional "test pinmask, ina wz" to properly set
the Z flag. Am I missing something obvious?
What is the result?
For example, I'm waiting on 2 pins to be in a certain state.. let's say..
pinstate = 0100
pinmask = 0110
If I do waitpeq pinstate, pinmask wz
What happens to the Z flag? I would expect it to be 0 as pinstate & pinmask <> 0
If I'm using waitpne pinstate, pinmask wz
If the pins are all clear, I'd expect the Z flag to be set, as pinstate & pinmask == 0.
I'm not seeing this behaviour however. I have to do an additional "test pinmask, ina wz" to properly set
the Z flag. Am I missing something obvious?
Comments
(2) Your guess "pinstate & pinmask" can not really be a possibility... Why should that be computed? I have the (shrude) suspicion that you think this is what WAITPEQ does. But is does not!
WAITPEQ state, mask
waits until state == (mask&ina)
(3) So mask&ina is computed and Z is set when THIS AND is zero, i.e. none of the masked pins is on.
(4) This means WAITPEQ will clear Z, except your requested state is really 0.
The flag could be slightly more useful with WAITPNE. However I have never needed it.
Post Edited (deSilva) : 9/30/2007 3:13:28 PM GMT
I did miscommunicate what I was doing.. I actually meant ina & pinmask.
If the pins 0 & 1 are both zero, then waitpne J, Mask wz (which is 0001 / 0011) should set the Z flag,
as ina & Mask == 0 .. this is not happening.
But where does he Know it from??
Post Edited (deSilva) : 9/30/2007 4:02:03 PM GMT
"if the WZ effect is specified, the Z flag will be set (1) if the result of INx ANDed with Mask is zero."
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Parallax Forums - If you're ready to learn, we're ready to help.
A %00 will stop the loop just before the jump and you might have read "old" values.
I have no magic sources of information other than many years of experience with a very wide range of computing hardware and software.
I try to read manuals carefully and I seem to have a good memory for detail. I also make mistakes, can be forgetful, and sometimes have strong opinions. CJ nicely found the answer in the manual and I was mistaken (again). Thank you.
Post Edited (Mike Green) : 9/30/2007 4:15:40 PM GMT
I have pin 0 pulled high and pin 1 pulled low with resistors..
If I short pin 0 to ground, the loop progresses.. (condition 0001 Mask 0011 ina 0000) but the Z flag is not set
According to the manual, it should be..
I've tested, re-tested and then tested again.. there must be something I'm missing.
I'm not reading old values because inserting
test mask, ina wz
*after* the waitpne that is *supposed* to clear the Z flag makes the reading correct..
If pin 1 is tied to ground (and it is), then the only way to make the loop run is to pull pin 0 low.. thus making both 1 & 0 low..
"and" that against the mask of %0011 and the result should be zero.. unless I'm very much mistaken.. %0000 & %0011 should be zero
I've double checked all the variables. J = %0001 K = %0010 Mask = %0011
My meter tells me at the time the loop progresses through that both pins 0 & 1 are 0v
the waitpeq J, Mask at the end of the loop ensures I don't repeat the test/wrlong until ina = %0001
Parallax ?? anyone?
The Z-Flag is always cleared, no matter if the Pin States AND ina results to Zero, or if you use WAITPNE or WAITPEQ.
Andy
Thanks Andy [noparse]:)[/noparse]
I'm pausing on one state (01), and with that flag I can tell if I've got both pins as zero (00), or the pins have both inverted (10).
When you have less than 26 cycles to play with in a loop.. 4 is a lot..
The extra instruction to detect the (00) state is somewhat unwelcome.
Doc says it should do it.. It don't do what it says on the tin..
Useless indeed...
-Phil
Wow, lot's of energetic discussion here. ;-)
The Mask is ANDed with INx first,·that result is·subtracted from State and if that resulting value·is 0, the condition is true, otherwise false.· For this reason, it is vital that State not have any 1s that don't correspond to 1s in Mask, else a WAITPEQ will never be true.
As for the Z flag:
I'll get an official answer as soon as I can, but it appears to me that Z is actually only set in the case where each of Mask and State are 0.· Of course, you can only see the result with a WAITPEQ because that's the only one that will move on in that case (regardless of the state of INx).
I still feel like I'm not seeing the entire picture here though... got to go to the source.· We'll clarify it here soon.· Sorry for the delay.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Jeff Martin
· Sr. Software Engineer
· Parallax, Inc.
Thanks for your patience.
Here is how the Z flag is affected by WAITPEQ and WAITPNE (with a WZ effect) according to lots of testing I've done.· We haven't confirmed this via the schematics yet, but we're pretty certain enough to tell you.
WAITPEQ: Z = 1 if State + Mask = 0.
WAITPNE: Z = 1 if State + Mask + 1 = 0.
Now, I don't think we really·intended for Z to be of any particular use with these two instructions, but rather let it be whatever it naturally ended up; just like with C.
That being said, I will be revising the docs to indicate that Z is undefined, just like C is, for those two commands.
Sorry for the confusion.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Jeff Martin
· Sr. Software Engineer
· Parallax, Inc.
A documentation update might be a good idea.
It *could* have been a useful flag..
Are there any cases where State + Mask = 0 (for Waitpeq wz) or State + Mask + 1 = 0 (for Waitpne wz) where z = 0? Or conversely,·does z always equal zero when neither of these cases are fulfilled?
It seems if both of these things are true, then z is not undefined but merely complicated.
Fred
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.