Shift-in/shift-out in a single package

Thread Starter

Edmunds

Joined Sep 27, 2010
85
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
 

crutschow

Joined Mar 14, 2008
34,285
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. ;)
 

Thread Starter

Edmunds

Joined Sep 27, 2010
85
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. ;)
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
 

Alec_t

Joined Sep 17, 2013
14,280
I'm having difficulty understanding that system, too. Also, it's not clear how all that switching relates to shift registers?
 

Bernard

Joined Aug 7, 2008
5,784
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.
 

Thread Starter

Edmunds

Joined Sep 27, 2010
85
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
 

Bernard

Joined Aug 7, 2008
5,784
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. ???
 

MMcLaren

Joined Feb 14, 2010
861
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:

crutschow

Joined Mar 14, 2008
34,285
........................
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.
Do the 3 relays need to be driven in any particular sequence (sequential, arbitrary, etc.)?
 

Brevor

Joined Apr 9, 2011
297
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:

Thread Starter

Edmunds

Joined Sep 27, 2010
85
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
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:

Thread Starter

Edmunds

Joined Sep 27, 2010
85
I'm thinking a micro with more pins is sounding like a good idea. :)
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
 

Thread Starter

Edmunds

Joined Sep 27, 2010
85
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.
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
 

MMcLaren

Joined Feb 14, 2010
861
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?
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

 

Attachments

Last edited:

MMcLaren

Joined Feb 14, 2010
861
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...
 

Thread Starter

Edmunds

Joined Sep 27, 2010
85
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


Thanks', makes sense.

Edmunds
 

MMcLaren

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

Rich (BB code):
  /******************************************************************
   *  variables and constants                                       *
   ******************************************************************/

   unsigned long swnew = 0;
   unsigned long swold = 0;
   unsigned long swcol = 0x00000008;
   unsigned long flags = 0;
   unsigned long outputs = 0;
   unsigned long packet = 0;
   
   #define swinput (PORTA & 1)
Rich (BB code):
    /*                                                              *
     *  sample one switch during each 1-msec update interval        *
     *                                                              */
       swnew = swold | swcol;   // indicate 'pressed'
       if(swinput)              // if not pressed (1)
         swnew ^= swcol;        // indicate 'released'
    /*                                                              *
     *  K8LH parallel switch state logic ('new press' filter)       *
     *                                                              *
     *  swnew __---___---___---__  sample active low buttons        *
     *  swold ___---___---___---_  switch state latch               *
     *  swnew __-__-__-__-__-__-_  changes, press or release        *
     *  swnew __-_____-_____-____  filter out 'release' bits        *
     *  flags __------______-----  toggle flag bits for main        *
     *                                                              */
       swnew ^= swold;          // changes, press or release
       swold ^= swnew;          // update switch state latch
       swnew &= swold;          // filter out 'release' bits
       flags ^= swnew;          // toggle flag bits for main
    /*                                                              *
     *  advance matrix column select bit (skip over output bits)    *
     *  sssssooo sssssooo sssssooo sssssooo  (s=switch o=output)    *
     *                                                              */
       if(swcol & 0x00000080) swcol = 0x00000400;
       if(swcol & 0x00008000) swcol = 0x00040000;
       if(swcol & 0x00800000) swcol = 0x04000000;
       if(swcol & 0x80000000) swcol = 0x00000004;

       swcol <<= 1;             // advance column select bit

    /*                                                              *
     *  update the 32 bit 74HC595 chain                             *
     *                                                              */
       packet = ~swcol;         // invert for active low select
       packet &= 0xF8F8F8F8;    // mask off output bit positions
       packet |= outputs;       // add the output bits
       SPIOut(packet);          // refresh 74HC595 chain
Not sure how difficult it would be to convert to BASIC (sorry).

Food for thought.

Cheerful regards, Mike
 
Top