Shop OBEX P1 Docs P2 Docs Learn Events
ls7166 quadradture reader chip — Parallax Forums

ls7166 quadradture reader chip

ArchiverArchiver Posts: 46,084
edited 2004-01-12 16:51 in General Discussion
hi everyone, has anyone used this chip that can get me started with
some example code? the chip has 8 data pins which are used to write
to its' control register and also to read the counter latch,, and
what i can gather from the spec sheet, the STAMP has to send a byte
to the control register to start the process of reading from the
counter latch. where i get lost is not knowing enough about accessing
and using this type of i.c. thanks in advance.

mark

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-01-12 16:51
    Mark, maybe I can help get you started. The example
    is based on wiring as follows:
    Stamp pin ls7166 pin
    P0/P7 D0/D7
    P8 CS
    P9 WR
    P10 RD
    P11 C/D
    Connect ls7166 pins 3 and 4 to 5volts (disable)

    'Code example
    ENC_COUNT VAR Word ' WORD to hold encoder count ls bytes
    ENC_COUNTHI VAR Byte 'BYTE to hold encoder count ms byte

    'Set initial STAMP2 I/O conditions
    DIRS = $0F00 'I/O pins 0-7=IN, 8-11=OUT
    OUTC = $F 'LS7166 CD=1, WR=1, RD=1, CS=1 (0 true)

    'Setup LS7166 initial conditions
    RESET:
    DIRL = $FF 'bus = output
    'Set OCCR count control register
    OUTL = $80 'count normal binary
    OUTC = $C 'CD=1, RD=1, WR=0, CS=0
    OUTC = $F 'CD=1, RD=1, WR=1, CS=1
    'Set QR register
    OUTL = $C3 'quadrature X4 mode
    OUTC = $C 'CD=1, RD=1, WR=0, CS=0
    OUTC = $F 'CD=1, RD=1, WR=1, CS=1
    'Set ICR input control register
    OUTL = $48 'enable A & B inputs
    OUTC = $C 'CD=1, RD=1, WR=0, CS=0
    OUTC = $F 'CD=1, RD=1, WR=1, CS=1
    'Reset counter via MCR register
    OUTL = $04 'reset counter
    OUTC = $C 'CD=1, RD=1, WR=0, CS=0
    OUTC = $F 'CD=1, RD=1, WR=1, CS=1

    'Main program loop
    LOOP:
    GOSUB READ_ENCODER 'go get the counts
    'insert code here to do something with the counts
    GOTO LOOP

    'Subroutine to read encoder count
    READ_ENCODER:
    'Reset address pointer and transfer count to Output Latch
    DIRL = $FF 'bus is output
    OUTL = $3 'reset OL address pointer, transfer CNTR to OL
    OUTC = $C 'CD=1, RD=1, WR=0, CS=0
    OUTC = $7 'CD=0, RD=1, WR=1, CS=1
    'Read encoder
    DIRL = $00 'bus is input
    OUTC = $2 'CD=0, RD=0, WR=1, CS=0
    ENC_COUNT.LOWBYTE = INL 'read ls byte of encoder
    OUTC = $6 'CD=0, RD=1, WR=1, CS=0
    OUTC = $2 'CD=0, RD=0, WR=1, CS=0
    ENC_COUNT.HIGHBYTE = INL 'read mid byte of encoder
    OUTC = $6 'CD=0, RD=1, WR=1, CS=0
    OUTC = $2 'CD=0, RD=0, WR=1, CS=0
    ENC_COUNTHI = INL 'read high byte of encoder
    OUTC = $7 'CD=0, RD=1, WR=1, CS=1
    RETURN


    Dennis


    In a message dated 1/10/04 5:38:49 PM Central Standard Time, >
    > From: "lakewood5982003" <598@m...>
    >
    > hi everyone, has anyone used this chip that can get me started with
    > some example code? the chip has 8 data pins which are used to write
    > to its' control register and also to read the counter latch,, and
    > what i can gather from the spec sheet, the STAMP has to send a byte
    > to the control register to start the process of reading from the
    > counter latch. where i get lost is not knowing enough about accessing
    > and using this type of i.c. thanks in advance.
    >
    > mark


    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.