Best way to implement an array of 64+ IR detectors?
outofstep
Posts: 3
I've got·a pro dev board and am using the 40 pin version of the stamp.
If it was a simple push button type input matrix, I could simply use the voltage divider setup of the POT command.
By default the IR detectors (link)·Vout +5 when not detecting, and 0 when they do detect; I am unsure of how to set up the circuit. Also, because the IR detectors are diodes, the POT setup shouldnt work (if running the IR detectors in parallel,·to make up for the constant on state)·because the voltage read stage should always read back 0.
The only way I've come up with is to use 8 8x3 encoders. However that will eat up 24 I/O lines. Is there a more elegant/efficient way to set this up?
I'm not sure if I explained everything correctly or not, just let me know if you need me to clarify something.
Post Edited (outofstep) : 3/2/2009 8:51:48 PM GMT
If it was a simple push button type input matrix, I could simply use the voltage divider setup of the POT command.
By default the IR detectors (link)·Vout +5 when not detecting, and 0 when they do detect; I am unsure of how to set up the circuit. Also, because the IR detectors are diodes, the POT setup shouldnt work (if running the IR detectors in parallel,·to make up for the constant on state)·because the voltage read stage should always read back 0.
The only way I've come up with is to use 8 8x3 encoders. However that will eat up 24 I/O lines. Is there a more elegant/efficient way to set this up?
I'm not sure if I explained everything correctly or not, just let me know if you need me to clarify something.
Post Edited (outofstep) : 3/2/2009 8:51:48 PM GMT
Comments
You can cascade 8 x 74HC165 to provide 64 inputs using only 3 I/O pins (clock, data, parallel load). The 74HC595 provides similar output expansion.
Post Edited (Mike Green) : 3/2/2009 9:14:58 PM GMT
It looks like I can break up the data coming in however I want. For an 8x8 matrix of sensors, I could assign an entire collumn or row a variable of its own.
SHIFTIN 0,1, mode, [noparse][[/noparse]row1\8, row2\8, row3\8, row4\8, row5\8, row6\8, row7\8, row8\8]
Post Edited (outofstep) : 3/6/2009 6:15:08 PM GMT
Mike, you've been very helpful in some of the other posts. How do I change my code here to reference a switch hanging off of the 2nd (and eventually 3rd, 4th, 5th...) chip?
Here is what I have:
'
[ I/O Definitions ]
Clock PIN 0 ' shift clock (74HC165.2)
SerData PIN 1 ' serial data (74HC165.7)
Load PIN 2 ' output latch (74HC165.1)
'
[ Constants ]
DelayTime CON 100
'
[ Variables ]
pedals VAR Word
xInputs VAR Word ' switch data
'
[ Initialization ]
Reset:
LOW Clock
HIGH Load ' make output and high
DEBUG CLS,
"Switches FEDCBA9876543210", CR,
"
", CR,
"Status"
'
[ Program Code ]
Main:
DO
GOSUB Get_165X2 ' get switch inputs
DEBUG CRSRXY, 10, 2, BIN8 pedals, BIN8 xInputs ' display current status
PAUSE delaytime
IF pedals.BIT0 = 1 THEN
HIGH 13
LOW 14
ELSEIF pedals.BIT1 = 1 THEN
HIGH 14
LOW 13
ELSEIF pedals.BIT8 = 1 THEN 'THIS PART IS NOT WORKING for BIT8-15!!!
HIGH 14
HIGH 13
ELSE
LOW 14
LOW 13
ENDIF
LOOP
'
[ Subroutines ]
Get_165X2:
PULSOUT Load, 5 ' load switch inputs
SHIFTIN SerData, Clock, MSBPRE, [pedals\8, xInputs\8] ' shift them in (IS THIS RIGHT?)
RETURN
'
[ Variables ]
pedals VAR Word
xInputs VAR Word ' switch data
'
[ Initialization ]
Reset:
LOW Clock
HIGH Load ' make output and high
DEBUG CLS,
"Switches FEDCBA9876543210", CR,
"
", CR,
"Status"
'
[ Program Code ]
Main:
DO
GOSUB Get_165X2 ' get switch inputs
DEBUG CRSRXY, 10, 2, BIN16 pedals ' display current status
PAUSE delaytime
IF pedals.BIT0 = 1 THEN
HIGH 13
LOW 14
ELSEIF pedals.BIT1 = 1 THEN
HIGH 14
LOW 13
ELSEIF pedals.BIT7 = 1 THEN
HIGH 14
HIGH 13
ELSE
LOW 14
LOW 13
ENDIF
LOOP
'LOW 12
'HIGH 14
'HIGH 13
'PAUSE 50
'LOW 14
'LOW 13
'ELSEIF switches.BIT0=1 AND switches.BIT1=1 AND switches.BIT5=1 THEN
'SEROUT 15,6,["#0 P500 #1 P1400 #2 P1600 #3 P1400",13]
'HIGH 13
'HIGH 14
'HIGH 12
'ELSE
'SEROUT 15,6,["#0 P750 #1 P1500 #2 P1500 #3 P1500",13]
'LOW 13
'LOW 14
'LOW 12
'ENDIF
'PAUSE DelayTime ' pad the loop a bit
'LOOP
'
[ Subroutines ]
Get_165X2:
PULSOUT Load, 5 ' load switch inputs
SHIFTIN SerData, Clock, MSBPRE, [pedals] ' shift them in
RETURN
Switches FEDCBA9876543210
Status 0000000001110000
The switches on the left 8 bits are not working. I have a switch on the pin that lines up with what I thought would be #8 (1st input from the second chip).
Any and all suggestions are greatly appreciated.
However, now I'm baffled by the code. Above outofstep suggests adding separate variables for each 74HC165:
"pedals1 VAR Word
pedals2 VAR Word
SHIFTIN 0, 1, MSBPRE, [pedals1\16, pedals2\16]
"
If I use this approach, how should I write the following:
1) The code to view all 24 (or more) inputs:
DEBUG CRSRXY, 10, 2, BIN16 pedals1 ' ??how do I reference the pins in pedals 2??
2) How do I reference each of the input pins on the 3rd register... I'm assuming I can use pedals1.BIT0 - pedals1.BIT15 ...or... pedals2.BIT0 - pedals2.BIT15
Am I thinking about this correctly?
2) Correct. The Manual also discusses bit arrays. You can refer to consecutive bits using a subscript and this can span adjacent variables like "pedals1.bit0(i)".
Each WORD variable has 16 bits.