"Shiftin" via a 76hc165
everest
Posts: 141
Hi,
I've got my 76hc165 all set up to read the state of switches by reporting a 1 or 0 depending upon the switch state. Is there some way to shift data into my Stamp2 via the 76hc165? At some point in the future I'm sure I'm going to need to do more that just read in a single Nib. . .?
-Jeff
I've got my 76hc165 all set up to read the state of switches by reporting a 1 or 0 depending upon the switch state. Is there some way to shift data into my Stamp2 via the 76hc165? At some point in the future I'm sure I'm going to need to do more that just read in a single Nib. . .?
-Jeff
Comments
That's exactly the reference I've been using, and that's the code I've implemented for reading my switches. I'm still not sure I understand how to do this though. . .as I read the code snippet I posted and the Stampworks Manual, when I do the "shiftin" I'm pulling the bit values for all of the individual pins, i.e. I get back: 11111111 or some combination depending upon the switch states. That makes perfect sense to me.
But let's say I have an ADC connected to one of those pins. . .if I were connected right to a Stamp2 pin I'd do a: SHIFTIN DataOutput,CLK,MSBPOST,[noparse][[/noparse]volts\8]. I'm very much a beginner but I think that says to read in 8 bits from the DataOutput pin. . .which represents the output of the ADC. But I can't see how to do that with the 74HC165.
Is it possible to shift in multiple bits from a single input on the 74HC165 in one shot? Do I need to do a loop to read in the 8 bits sequentially?
-Jeff
Re-read the description of SHIFTIN and SHIFTOUT in the Stamp Manual.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
In that source code (see below) there is this statement:
SHIFTIN SerData, Clock, MSBPRE, [noparse][[/noparse]switches] ' shift them in
This moves one bit of data associated with each pin on the 74HC165. In the simple experiment in the Stampwork manual this is used to read in 8 bits, one for each pin on the 74HC165. This works just perfectly, but one bit really doesn't do a whole lot for me if I'm using anything but simple switches.
My question is this: How do I read in MORE than one bit on a given 74HC165 pin. Let's say I wanted to read the data from an ADC0831 in the configured shown in the attached schematic. . .the following code has my questions embedded:
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] I/O Definitions ]
Clock PIN 0 ' shift clock (74HC165.2)
SerData PIN 1 ' serial data (74HC165.7)
Load PIN 2 ' output latch (74HC165.1)
CS PIN 3 ' chip select (ADC0831.1)
Clock PIN 4 ' clock (ADC0831.7)
DataIn ????? ' HOW DO I SPECIFY THAT I WANT TO USE A 74HC165 PIN? ***
'
[noparse][[/noparse] Constants ]
Cnts2Mv CON $139C ' x 19.6 (to millivolts)
DelayTime CON 100
'
[noparse][[/noparse] Variables ]
result VAR Byte ' result of conversion
mVolts VAR Word ' millivolts
'
[noparse][[/noparse] Initialization ]
Reset:
DEBUG CLS, ' create report screen
"ADC.... ", CR,
"volts... "
'
[noparse][[/noparse] Program Code ]
Main:
DO
GOSUB Read_0831 ' read the ADC
mVolts = result */ Cnts2Mv ' convert to millivolts
DEBUG HOME, ' report
CRSRXY, 9, 0, DEC result, CLREOL,
CRSRXY, 9, 1, DEC mVolts DIG 3,
".", DEC3 mVolts
PAUSE 100
LOOP
'
[noparse][[/noparse] Subroutines ]
Read_0831:
LOW CS ' enable ADC
SHIFTIN ??????, Clock, MSBPOST, [noparse][[/noparse]result\9] ' AGAIN I NEED TO READ DATA FROM ONE 74HC165 INPUT? ***
HIGH CS ' disable ADC
RETURN
Shoot, I wish I'd read your post earlier. . .sounds like my question is answered. . .the 74HC165 can't do this. . .? So now I have to go back to a question I asked a few weeks back. . .how can I *really* expand the number of I/O pins on my Stamp2 module?
I have a sensiron temp/humidity sensor, an ADC0831, a Ping)) unit, and an MLX90614. So between all of those I'm consuming an awful lot of I/O pins. . .I really need to reduce the number I'm using for my application. Is there another way to get additional fully functional I/O pins? Is it possible to share pins between the units I've listed? Any hints/approaches would be much appreciated.
-Jeff
The MLX90614 doesn't seem to have a "Clock" line, is there anything there I can share as well? How about the Signal/Data lines? If nothing is enabled but one of the units, couldn't those chips all share the same Stamp2 pin?
-Jeff
That still leaves 11 I/O pins. What do you plan to do with those?
The 74HC165 is really useful for reading switch closures and status logic levels that don't change very quickly (maybe 100 times a second).
The 74HC595 is really useful for controlling logic level devices where delays of a few milliseconds are acceptable.
Post Edited (Mike Green) : 9/8/2009 6:10:53 PM GMT
THANKS! The limitations are more clear to me now. So I'm using the following sensors. . .can you help me more clearly identify which pins I can safely share?
ADC0831: Chip Select, Clock, Data
74HC165: Load, Clock, Data
Sensiron: Clock, Data
MLX90614: Reset, Alarm, Signal (Data?)
Ping)): Signal (Data?)
So right now I'm consuming 12 pins to drive these devices. . .the rest of my application is consuming the remaining 4 as output pins. I know I could save some additional pins with a 74HC595, but looking just at the 5 devices above. . .I'd like to save as many there as possible. Thanks for any suggestions!
-Jeff
-Jeff
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
-Jeff