Sx/B XOR
duffling
Posts: 73
Im confused as to how i XOR two BIT values using SX/B or assm
Im reading an encoder and need to XOR two bits appearing on Rb.0 , and Rb.1
basically I capture the Encoder state ,
then XOR the Oldstate SecondBit with the NewState first bit to work out the direction of rotation
slightly confused..
·
Im reading an encoder and need to XOR two bits appearing on Rb.0 , and Rb.1
basically I capture the Encoder state ,
then XOR the Oldstate SecondBit with the NewState first bit to work out the direction of rotation
slightly confused..
·
Comments
I assume you can only XOR bytes and not individual bits ? which is really what my question should have been.
thanks again.
Post Edited (duffling) : 4/25/2005 4:01:41 AM GMT
its
encNew = EncPort & %00000011· i understand its performing a Bit wise AND operation
but why is this nessicary ? and.
im still having real troubles getting my encoder to work ... so any help is most welcome
I dont have the grayhil part , but the encoder i have is similar , it has 3 pins with the center being a ground , and A , B pins
it has a 4 bit cycle ,
with a pattern like :
11·· ( indent position )
01
00
10·············· clockwise··· -->
i have it wired , with VSS to encoder center pin·and Resitors for each encoder pin from VDD to Rb.0 , Rb.1
thanks again.
Post Edited (duffling) : 4/25/2005 11:51:33 AM GMT
You are correct. You cannot XOR individual bits. The SX does not provide this in assembly either. You must do as Jon has done, and mask out the bits you are interested in an use the byte XOR.
Also if you just want to test, XOR means "Not Equal" so you can do:
IF MyBit1 <> MyBit2 GOTO Somewhere ' Same as IF (MyBit1 XOR MyBit2) = 1
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video Display Module" Available Now.
www.sxvm.com
"A problem well defined, is a problem·half solved."
Post Edited (Bean) : 4/25/2005 12:12:07 PM GMT
mov w,>>rb ;mov rb.1 to w.0
xor w,rb ;xor w.0 with·rb.0
and w,#1 ;extract result
jnz not_equal
This·works for two bits·next to each other,
(not necessarily same byte)
regards peter
But im getting there
basically im missing inbetween bits as the knob travels from one state to another .. so i assume im going to have to check for incorrect bits as well
i will keep trying .. your suggestions are most helpful
Can you post your code. That will help us help you.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video Display Module" Available Now.
www.sxvm.com
"A problem well defined, is a problem·half solved."
·
thanks again.
As Paul Baker·mentions, the key is NEVER missing a transition and so the use of the port B interrupt pending flags (with or without an interrupt) is a great trick. Sadly, I've never seen code written that uses that.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james@sxlist.com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!