Shop OBEX P1 Docs P2 Docs Learn Events
Sx/B XOR — Parallax Forums

Sx/B XOR

dufflingduffling Posts: 73
edited 2005-04-25 18:26 in General Discussion
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..
·

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-04-24 21:19
    Have you looked at Jon Williams SX/B example program for encoders that is included with the SX/B distribution?
  • dufflingduffling Posts: 73
    edited 2005-04-25 03:13
    Yes i Just had a look at it , How did I miss that ?

    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
  • dufflingduffling Posts: 73
    edited 2005-04-25 11:44
    One line i dont quite understand is the one in the Quad encoder demo project in SX/B documentation

    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
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-04-25 11:58
    The encNew line is doing an AND to mask out only the bits we are interested, since the encoder has two bits of information, Data & %0000011 returns only the value of what the last two bits in Data are. Can you provide a little more detail on what problem·specifically you are having, are you receiving the data correctly? (ie are you having software or hardware issues?)
  • BeanBean Posts: 8,129
    edited 2005-04-25 12:07
    Duffling,
    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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-04-25 14:20
    You could do

    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
  • dufflingduffling Posts: 73
    edited 2005-04-25 16:44
    The hardware is working properly i think .. im having problems getting my head around the software really .. since its the first time ive used Quad Encoders before
    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
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-04-25 17:13
    The key to using encoders is that you must detect each and every transition of the encoder, if you miss one, say your in state 00 and your next detected state is 11, you have no way of knowing whether it went through state 01 or 10 to get to your current state, this is important because you have detected that there was a transition of 2 states but you cannot determine whether the movement was clockwise or counter-clockwise. If you are missing transitions as you seem to be indicating you need to increase the sampling frequency by reducing the time between RTCC rollovers. You could also use port B interrupt on the two pins to be sure you enter your ISR to deal with the transition as soon as it occurs, but many of the experienced programmers in this forum suggest not doing this, there are several reasons why but the main one is if the port B interrupt and RTCC interrupt are used, there is the distinct possibility of missing an interrupt if you are processing another interrupt source.
  • BeanBean Posts: 8,129
    edited 2005-04-25 17:16
    Duffling,
    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."
    ·
  • dufflingduffling Posts: 73
    edited 2005-04-25 17:40
    I will rewrite it with the above tips in mind and send the code if i still have problems

    thanks again.
  • James NewtonJames Newton Posts: 329
    edited 2005-04-25 18:26
    See http://www.sxlist.com/techref/ubicom/lib/io/osi1/sensor/qenc_sx.htm for Quadrature decoding.

    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!



Sign In or Register to comment.