9555 GPIO vs. SN74151

When I need additional digital inputs or outputs, I usually use the 9555. The down side is that the I2C library stops interrupts and one message read/write to the 9555 takes something on the order of 350 usec. This not terrible, except if you have a system that requires time-critical interrupts.

TTL technology and circuits are about a billion years old, but it still has some very useful chips. You can interface with two 74HCT251 chips using only six pins and you get 16 inputs in return. A full handshake with them takes only 17 usec and best of all, the 74151 interface code doesn't care if it gets interrupted.

I'm using this for switch detection input to an 8-circuit phase cut dimmer run by a nano.

The code to input from 2 74151s uses pins 5,6,7 as the address lines and pins 3,4 to read the output pins of the 74151s. The switch_array is a tripple buffer for doing debounce on the inputs from pin 3 (these are mechanical switch inputs on the 74151). The other 74151 (pin 4) is connected to sensors and doesn’t require debounce. This code runs in 30 usec.

 Port_1 = 0 ; // switches
 Port_2 = 0 ; // sensors = bits 0-4, ID = bits 5-7
 for(i=0; i<8; i ++) {  // i is the bit pointer
   // the first shift (i = 0) is meaningless
   //   (subsequent shifts preserve previously read bits)
   Port_1 = Port_1 >> 1 ; // shift up for next read operation
   Port_2 = Port_2 >> 1 ; // move the bits up for next read
   // write the address to PortD high pins
   PORTD = (PIND & 0x1F) | i << 5 ; // load the address
   // read the LSB into the two port variables
   Port_1 = Port_1 | (PIND & 0x08) << 4 ; // read PortD bit 3
     // into the high order bit, to be shifted right in each loop
   Port_2 = Port_2 | (PIND & 0x10) << 3 ; // read PortD bit 4   
   } // exit i loop; reads both bytes for switches and sensors
  // roll down the switch array and assign the newest sample
  switch_array[2] = switch_array[1] ;
  switch_array[1] = switch_array[0] ;
  switch_array[0] = Port_1 ;

Besides being fast, the 74151 has significant noise immunity when it's inside a box that is switching 115V light circuits. I've found that the 9555 does a power-on reset if the noise is high enough. This requires the nano to constantly monitor it and to reset the ports to output and resend the port byte in order to restore the intended control status.

Unfortunately this part is obsolete, but you can get similar performance in a 74HC4051, but only in an SO16 package, which is a bit more difficult to solder.

The 9555 has the advantage of fewer interconnecting wires. You can send 16 control bits to a relay box with only 4 wires.