Shop OBEX P1 Docs P2 Docs Learn Events
"Shiftin" via a 76hc165 — Parallax Forums

"Shiftin" via a 76hc165

everesteverest Posts: 141
edited 2009-09-09 04:37 in BASIC Stamp
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 15:17
    Look in the Stampworks Manual, experiment #24 for a discussion and examples of the use of a 74HC165. The SHIFTIN statement is what is used.
  • everesteverest Posts: 141
    edited 2009-09-08 16:19
    Hi Mike,

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 16:49
    The 74HC165 works with the SHIFTIN statement as discussed in the Stampworks Manual. If it's not working for you, you will need to draw a schematic of exactly how you've connected everything and attach the scanned schematic to a message along with attaching the source code that you're using. There's something wrong with what you're doing and it's impossible to tell what that is without more information.

    Re-read the description of SHIFTIN and SHIFTOUT in the Stamp Manual.
  • FranklinFranklin Posts: 4,747
    edited 2009-09-08 17:12
    The chip will only report high or low on a pin. You can't communicate through it as you suggested.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • everesteverest Posts: 141
    edited 2009-09-08 17:31
    Sorry Mike, I'm not being very clear. My 74HC165 is working just fine. I'm using the schematic exactly as shown in the Stampworks Manual and the exact same source code.

    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
    934 x 480 - 64K
  • everesteverest Posts: 141
    edited 2009-09-08 17:36
    Franklin,

    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
  • everesteverest Posts: 141
    edited 2009-09-08 17:49
    Working through all of these Stampworks projects, it looks like I can at the very least share a Clock line between the ADC0831, and the Sensiron. . .assuming I give them each a dedicated Load/CS line couldn't I just enable the unit I want to read at some point in my code, and use the same Clock line for both? That would save me one pin I'd think.

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 17:59
    There is no way to use an I/O expander to get additional "fully functional" I/O pins. You could share the data pins of the ADC0831 and the Sensiron sensor with a separate clock pin for each, but the PING and MLX90614 need their own I/O pins. The MLX90614 uses an asynchronous serial interface and the PING uses a bidirectional control line with its own convention. That's a total of 5, ADC0831-2, Sensiron-1 w. 1 shared with ADC0831, PING-1, MLX90614-1.

    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
  • everesteverest Posts: 141
    edited 2009-09-08 18:45
    Mike,

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 18:54
    Like I said, you can share the ADC0831 and Sensiron Data pins. You may not need either the Alarm or the Reset signals of the MLX90614 and you could leave them unconnected if so.
  • everesteverest Posts: 141
    edited 2009-09-08 19:39
    Thanks Mike! Looking again at the MLS90614 demo code and specifications, I don't think I need to use the Alarm and Reset pins on that unit. So that saves me three pins. Thanks!

    -Jeff
  • FranklinFranklin Posts: 4,747
    edited 2009-09-09 03:55
    You could also use an ADC with more analog inputs and the same three pins to read them all for the analog inputs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • everesteverest Posts: 141
    edited 2009-09-09 04:37
    I think I'm good for now. . .I've got a handful of pins now to expand with if necessary. . .thanks everyone! The IR sensor works fine with just one pin, and sharing the data pin between the ADC and Sensiron works perfectly.

    -Jeff
Sign In or Register to comment.