Shift-in/shift-out in a single package

Discussion in 'The Projects Forum' started by Edmunds, Jul 4, 2014.

  1. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0
    Dear all,

    Digging my way through the landscapes of digital electronics I'm now into shift registers. I need to control 4 groups of four analog (on/off, hope I'm using the definition correctly) inputs and 3 to 4 analog outputs each. Ideally in 4 SMD/SMT packages. Ideally with four data lines (one four each group) and a single clk line shared between the four. And possibly some "enable" or latch signal. Again, preferably one to share. Is this possible and if yes, with what part?

    Thank you for your input,

    Edmunds
     
  2. crutschow

    Expert

    Mar 14, 2008
    12,982
    3,221
    It's not clear what you need. :confused:

    Are you just trying to switch 4 groups of 4 analog signals on and off? If so then you just need 4 sets of 4 analog switches controlled by 4 control lines, no clock needed.

    Or are you trying to switch each of the 4 signals in each group sequentially but simultaneous with the other 3 groups?

    What do you mean 3 or 4 analog outs? Is that per group?

    So tell me what you need, not how you might do it. ;)
     
  3. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0
    Thanks', attempt #2.

    There are 4 DIP switches, where user selects some parameters. There is one reed switch. There are 3 optocouplers to switch 3 outputs. This is one group.

    There is a total of four groups. Why I'm grouping them is because I want to keep the hardware separate - it is difficult for various reasons to have two groups to share a register or optocoupler array, for an example.

    There are 12 more inputs that are general - relevant to all four groups.

    There is one input per group that has to go to the MCU directly.

    There is one output per group that will be served by a slave MCU - takes one output from the master MCU.

    There is a 16 or max 17 output master MCU that has to run all of this i.e. switch outputs depending on the inputs and many of them simultaneously and independent of each other.

    I hope this makes more sense.

    Edmunds
     
  4. crutschow

    Expert

    Mar 14, 2008
    12,982
    3,221
    Still sorta hard to follow. Could you draw and post a block diagram of what you have/want?
     
  5. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    5,771
    1,103
    I'm having difficulty understanding that system, too. Also, it's not clear how all that switching relates to shift registers?
     
  6. Bernard

    AAC Fanatic!

    Aug 7, 2008
    4,170
    395
    Not really.
    Only semi sure is that one side of DIP SW goes to ground or Vdd.
    Are you sure that some of the signals are analog?
    How about a sketch.
     
  7. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0
    Oki, sorry for that, attempt #3.

    Forget everything written above.

    Pls help me read the state of 5 switches to ground or vdd (really does not matter) and drive 3 low power relays with a single data line (serial, I guess) from mcu.

    Edmunds
     
  8. Bernard

    AAC Fanatic!

    Aug 7, 2008
    4,170
    395
    2 nd part:
    Assume relays operate independently with on- off command. Use digilal comparator or 2, for each relay. Each comparator progammed with a 4 bit code. As data sweeps by a comp. sees its code and sets a flip-flop which turns on a relay driver, FET, & relay. Relay stays on untill off code received. ???
     
  9. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,379
    494
    On/Off+data=digital
     
  10. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Is each 'group' identical? That is, 5 inputs and 3 outputs? If so, and if I understand your requirements correctly, you can do it using four 74HC595 or similar serial-to-parallel shift registers, twenty 1N914/1N4148 signal diodes, and four I/O pins (Clock, Data, Latch, and Input)...

    From a software standpoint, it would be better to dedicate each 74HC595 to a set of eight inputs or outputs, so one, two, or three 74HC595's for 8,16, or 24 inputs, respectively, and one, two, or three 74HC595's for 8, 16, or 24 outputs, respectively. It will still require only four I/O pins.

    Mike
     
    Last edited: Jul 4, 2014
  11. crutschow

    Expert

    Mar 14, 2008
    12,982
    3,221
    Do the 3 relays need to be driven in any particular sequence (sequential, arbitrary, etc.)?
     
  12. Brevor

    Active Member

    Apr 9, 2011
    279
    54
    Sounds like you are looking for an "I/O expander" One IC that is controlled serially and has both inputs and outputs. The PCF8574 comes to mind. It has 8 I/O lines, It uses I2C to communicate so it requires 2 lines from the MCU.

    Microchip makes 2 versions with 16 I/O lines, MCP23017 is I2C controlled and MCP23S17 is SPI.
     
    Last edited: Jul 4, 2014
  13. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    I'm thinking a micro with more pins is sounding like a good idea. :)
     
  14. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0
    Mike, thank you.

    I was looking that way, but cannot see how to get the 74HC595 to work with both - inputs and outputs. How would you read the state of the inputs at the same time (not necessarily the same nanosecond, though) while switching the outputs? Can you explain the concept, please?

    And where would the diodes go?

    I understand I might have to revert back to separating outputs and inputs for software reasons due my programming skill level among them, but I'm willing to learn as much as possible here and explore the option of having a device per group.

    Edmunds
     
    Last edited: Jul 5, 2014
  15. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0
    Thanks', have considered, but the limit is 40 anyway for picaxe system that I'm comfortable with and that would not be enough. On top of that, the 20pin chip has a number of features I think will come in handy that the 40 does not have.

    Edmunds
     
  16. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0
    Brevor,

    Thanks' a lot, this seems like the prime way to investigate further. As with so many things, what you need these days with all the internet at your fingertips is not the solution itself, but somebody to suggest the right google keywords :).

    The PCF8574 with its INT pin option and reasonable price seems a good way to go, so I have ordered a couple and let's see what I can achieve with I2C when they arrive.

    Edmunds
     
  17. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Read one switch at a time by loading the shift registers with a "walking zero" pattern that drives a single line of the switch matrix low. Switches are connected to 74HC595 outputs through a diode. The other side of all the switches are connected to the 'Input' pin (with pull-up). Load the 74HC595 shift registers at 1 or 2 msec intervals with 32 bits (the 20 bit "walking zero" pattern to drive the switch matrix and your 12 output bits) and you get an effective 20 or 40 msec debounce interval. The method is not unlike that used for the simple LCD + I/O interface depicted below.

    Good luck on your project.

    Cheerful regards, Mike

    [​IMG]
     
    Last edited: Jul 5, 2014
    absf likes this.
  18. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    RB's suggestion also makes sense when you consider that you can read all of the matrixed switches on a single pin... so 20 switches and 12 outputs plus 1 input = 33 pins...
     
  19. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0

    Thanks', makes sense.

    Edmunds
     
  20. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    It seems putting 5 inputs and 3 outputs on each 74HC595 isn't the software headache I thought it might be;

    Code ( (Unknown Language)):
    1.   /******************************************************************
    2.    *  variables and constants                                       *
    3.    ******************************************************************/
    4.  
    5.    unsigned long swnew = 0;
    6.    unsigned long swold = 0;
    7.    unsigned long swcol = 0x00000008;
    8.    unsigned long flags = 0;
    9.    unsigned long outputs = 0;
    10.    unsigned long packet = 0;
    11.    
    12.    #define swinput (PORTA & 1)
    13.  
    Code ( (Unknown Language)):
    1.  
    2.     /*                                                              *
    3.      *  sample one switch during each 1-msec update interval        *
    4.      *                                                              */
    5.        swnew = swold | swcol;   // indicate 'pressed'
    6.        if(swinput)              // if not pressed (1)
    7.          swnew ^= swcol;        // indicate 'released'
    8.     /*                                                              *
    9.      *  K8LH parallel switch state logic ('new press' filter)       *
    10.      *                                                              *
    11.      *  swnew __---___---___---__  sample active low buttons        *
    12.      *  swold ___---___---___---_  switch state latch               *
    13.      *  swnew __-__-__-__-__-__-_  changes, press or release        *
    14.      *  swnew __-_____-_____-____  filter out 'release' bits        *
    15.      *  flags __------______-----  toggle flag bits for main        *
    16.      *                                                              */
    17.        swnew ^= swold;          // changes, press or release
    18.        swold ^= swnew;          // update switch state latch
    19.        swnew &= swold;          // filter out 'release' bits
    20.        flags ^= swnew;          // toggle flag bits for main
    21.     /*                                                              *
    22.      *  advance matrix column select bit (skip over output bits)    *
    23.      *  sssssooo sssssooo sssssooo sssssooo  (s=switch o=output)    *
    24.      *                                                              */
    25.        if(swcol & 0x00000080) swcol = 0x00000400;
    26.        if(swcol & 0x00008000) swcol = 0x00040000;
    27.        if(swcol & 0x00800000) swcol = 0x04000000;
    28.        if(swcol & 0x80000000) swcol = 0x00000004;
    29.  
    30.        swcol <<= 1;             // advance column select bit
    31.  
    32.     /*                                                              *
    33.      *  update the 32 bit 74HC595 chain                             *
    34.      *                                                              */
    35.        packet = ~swcol;         // invert for active low select
    36.        packet &= 0xF8F8F8F8;    // mask off output bit positions
    37.        packet |= outputs;       // add the output bits
    38.        SPIOut(packet);          // refresh 74HC595 chain
    39.  
    Not sure how difficult it would be to convert to BASIC (sorry).

    Food for thought.

    Cheerful regards, Mike
     
    absf likes this.
Loading...