Shop OBEX P1 Docs P2 Docs Learn Events
Problems interfacing a LS7166 with an optical encoder to a bs2 — Parallax Forums

Problems interfacing a LS7166 with an optical encoder to a bs2

Geoffrey LewisGeoffrey Lewis Posts: 3
edited 2005-02-19 23:50 in BASIC Stamp
I'm currently working a project that needs to interface a LS7166 with an optical encoder to a bs2.· I have had no luck with this.· I only get zeros past back from the ls7166.· Below is my code.· I have read thru the older archives on this forum and found others have tried this and had trouble, but no one has ever stated that they actually got this to work.

Thanks,
Geoffrey Lewis

'{$STAMP BS2sx}·
'{$PBASIC 2.5}
·
DataBus······VAR···· Byte(3) ' Data read in from DataBus
Index········· VAR···· Byte··· ' index counter
Position······ VAR···· Word··· ' Current Encoder position as of last read
·
'---[noparse][[/noparse] LS7166 connection ]

·
'
[noparse][[/noparse] bsp24 Pins ]
[noparse][[/noparse] LS7166 pins ]

Readbit······· PIN 5············ ' READ-Lo
pin19
ControlBit···· PIN 6············ ' Control/Data Input - pin18
Writebit······ PIN 7············ ' Write
pin1
·
'············· PIN 8·············· Data bus
pin8
'············· PIN 9······ ········Data bus
pin9
'············· PIN 10············· Data bus
pin10
'············· PIN 11············· Data bus
pin11
'············· PIN 12············· Data bus
pin12
'············· PIN 13············· Data bus
pin13
'············· PIN 14············· Data bus
pin14
'············· PIN 15············· Data bus
pin15
'
'································· Ground
pin2· chip SELECT
'···························· ·····+5vdc
pin3· Tied to +5vdc
'································· +5vdc
pin4· Tied to +5vdc
'································· +5vdc
pin5· Tied to +5vdc
'································· Ground
pin20 ground
·
'---[noparse][[/noparse] Start of executable code ]

·
··· DEBUG CLS
·
··· OUTPUT Writebit············· ' Initialize BASIC Stamp pins as outputs to LS7166
··· OUTPUT ReadBit
··· OUTPUT ControlBit
·
··· GOSUB resetLS7166
·
··· ' Read the LS7166 - loop forever
·
··· DO
····· GOSUB ReadLS7166
····· DEBUG CRSRXY,0,8,"Position = ",DEC5 Position, CLREOL
··· LOOP
··· END
·
'---[noparse][[/noparse] Subroutines ]

·
'
[noparse][[/noparse] resetLS7166 ]

·
ReadLS7166:
·
··· Writebit = 1
··· ReadBit = 1
·
··· DIRH = %00000000······ ' Set pins 15 thru 8 as Inputs
·
··· ControlBit = 1
·
··· OUTH = $03
··· GOSUB LS7166Strobe
·
··· OUTH = $08
··· GOSUB LS7166Strobe
·
··· ControlBit = 0
·
··· FOR index = 0 TO 2
······· ReadBit = 0
······· DataBus(index) = INH
······· ReadBit = 1
······· DEBUG CRSRXY,0,10+index,"databus(",DEC index,")", DEC databus(index), CLREOL
··· NEXT
··· Position.HIGHBYTE = DataBus(1)
··· Position.LOWBYTE = DataBus(0)
··· RETURN
·
'
[noparse][[/noparse] LS7166Strobe ]

LS7166Strobe:
··· writebit = 0
··· writebit = 1
··· RETURN
·
'
[noparse][[/noparse] resetLS7166 ]

resetLS7166:
·
··· ' Initialize MCR
·
··· ControlBit = 1················ ' "1"······ Setting for MCR
·
··· ReadBit = 1··················· ' "1"······ Setting for MCR
··· Writebit = 1
·
··· DIRH = %11111111·············· ' Set pins 15 thru 8 as outputs
·
··· ' MCR
··· OUTH = $20
··· DEBUG CRSRXY,0,1,"MCR OUTH = ", BIN8 OUTH," HEX ",HEX2 OUTH, CLREOL
··· GOSUB LS7166Strobe
·
··· ' MCR
··· OUTH = $04
··· DEBUG CRSRXY,0,1,"MCR OUTH = ", BIN8 OUTH," HEX ",HEX2 OUTH, CLREOL
··· GOSUB LS7166Strobe
·
··· ' ICR
··· OUTH = $48
··· DEBUG CRSRXY,0,2,"ICR OUTH = ", BIN8 OUTH," HEX ",HEX2 OUTH, CLREOL
··· GOSUB LS7166Strobe
·
··· ' OCR
··· OUTH = $B0
··· DEBUG CRSRXY,0,3,"OCR OUTH = ", BIN8 OUTH," HEX ",HEX2 OUTH, CLREOL
··· GOSUB LS7166Strobe
·
··· ' QCR
··· OUTH = $C1
··· DEBUG CRSRXY,0,4,"QCR OUTH = ", BIN8 OUTH," HEX ",HEX2 OUTH, CLREOL
··· GOSUB LS7166Strobe
·
··· ControlBit = 0
·
··· RETURN·

Comments

Sign In or Register to comment.