PDA

View Full Version : Problems interfacing a LS7166 with an optical encoder to a bs2



Geoffrey Lewis
02-18-2005, 07:46 AM
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
·
'---[ LS7166 connection ]-------------------------------------------------------
·
'----------[ bsp24 Pins ]--------------------------[ 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
·
'---[ 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
·
'---[ Subroutines ]-------------------------------------------------------------
·
'------------[ 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
·
'------------[ LS7166Strobe ]---------------------------------------------------
LS7166Strobe:
··· writebit = 0
··· writebit = 1
··· RETURN
·
'------------[ 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·

Bruce Bates
02-20-2005, 06:04 AM
Geoffrey -

The attached PDF was referenced in a earlier discussion about the LS166 on the old Yahoo Stamp List. You may find it helpful in finding your problem.

Regards,

Bruce Bates

Chris Savage
02-20-2005, 07:50 AM
Here's a link to some test code for interfacing the LS7166 to a BS2.

http://users.etown.edu/w/wunderjt/BOEbot/robot/BSLS7166test.htm



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--==<{Chris}>==--