Shop OBEX P1 Docs P2 Docs Learn Events
RotaryEncoder.spin — Parallax Forums

RotaryEncoder.spin

Richard S.Richard S. Posts: 70
edited 2007-01-22 04:27 in Propeller 1
Rotary Endocer....

The assembly code labeled 'update' initiated by cognew...

I need help in understanding the first several lines...

· update··· test··· Pin, #$20
···············muxc· :PinSrc, #$1

I understand the 'test' function but donot understand why #$20 (0010 0000) was chosen as the mask.

The comment states that the·'muxc :PinSrc, #$1'....'adjusts :PinSrc instruction for proper port'.· ???· I see no calls to ':PinSrc label'...what is it used for?· Likewise, I see no calls to ':IPos label'...what is it used for?

Further down there are

·············· mov·· St2, ina
·············· |
·············· mov·· St2, inb

I·thought INB was not available.· Is this an error?

I have top calling routine, a modified VGA_TEXT.spin, VGA.spin and RotaryEncoder.spin.· I do not have a gray scale encoder. The RotaryEncoder.spin will not work with quadrature encoders.··If I make and break encoder pin connections to the cpu input port, the counters will increment somewhat.·

I have a routine to convert gray scale back to binary· which could be grafted into the rotaryencoder.spin code and it is as follows:

· gc = (bn>>)^bn· 'to convert binary bn to Gray code gc

I also have Matthew Ballinger's quadrature encoder routine written in parallax mneumonics...

ChkEnc··mov·· new, Enc··············· ;get new input
··········· and··· new,#%00000011··· ;get rid of all but 2 enc bits
··········· mov·· temp,new············· ·;make copy
··········· xor···· temp,old·············· ·;is old = new
··········· jz······ ChkEnc················· ;then no change, go back
·········· ·cje·····temp,#3,err··········· ;goto "error" if both bits changed
··········· clc·································;get ready for right shift
··········· rl······· old······················· ;align bits
··········· xor···· old,new················· ;check for direction
··········· jb······ old.1,up················ ;if 1 then up direction, if 0 then down direction

I am attempting to splice this in to rotaryencoder.spin!

Any help in understanding the RotaryEncoder.spin assembly code would be appreciated.



··········






▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Richard in Michigan

Comments

  • John CulverJohn Culver Posts: 5
    edited 2007-01-22 03:40
    The :PinSrc is the address of the io read instruction (mov st2, inb), not a subroutine. Those 2 instructions are checking if the pin number is in the range 0..31 or 32..63 and modifying the io address accordingly with the·muxc instruction·altering the source of the input read between ina and inb which only differ in their low bit.

    test··· Pin, #$20·············· wc

    · If the pin number is in the range 32..63 the carry is set.· If the pin number is in the range 0..31 the carry is cleared

    muxc··· :PinSrc, #%1

    ··By copying the carry into the low bit of the :PinSrc instruction the instructions source address·gets changed between ina and inb. This replaces the low bit of the address so inb is only used when requested by Pin numbers 32..63.inb will be used if the pin number is 32 or more, ina for 0..31. This should support 64 io pin propellor chips.

    The initial read of the inputs (mov st2, ina)·ought to have had the same self modifying code applied to it, but that's a minor detail.

    RotaryEncoder aka QuadratureEncoder works well as·a 1 to 16·incremental quadrature encoder interface. I have tested it succesfully on actual quadrature encoders. I have faster versions for smaller numbers of encoder incremental interfaces.
  • Richard S.Richard S. Posts: 70
    edited 2007-01-22 04:27
    Thanx for the reply, John.

    I will work through the info you gave.

    Your last statement...are you saying that the rotaryencoder.spin works ok with quad. encoders? If so, then I have a problem!

    I would like to have up to 4 quad encoders...I do not see a need for delta. Would eventually like to interface to a keyboard to change encoder value, etc.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Richard in Michigan
Sign In or Register to comment.