Go Down

Topic: 74HC166 as 8 port input chip (Read 1 time) previous topic - next topic

sliderule

Apr 18, 2016, 08:38 am Last Edit: Apr 18, 2016, 08:44 am by sliderule
I find lots of comments on using the 76HC165 as an input, but there seems to be problems with the 166. As I found I had a few and needed some extra inputs I had pulled together a bit of code that seems to be working just fine.

As you can see in the picture I bread boarded the 74HC166 together with a pair of hexadecimal rotary dip switches. This allows me to select input from 00 to FF hexadecimal very easily.

On the output side I am use the all to familiar 74HC595 you all seem to know how it connects so no worries there. I connected the 595 to a single 7 Segment Led display just to give it something to indicate on.

In my first attempt I was concerned with pin 15 the load/shift function of the 166 and the need to supply clocking to the chip on pin 7 to make it function. My original plan was to write a serial Input routine and not use shiftIn, but of course the urge to make a short cut was strong so I took a shot with shiftIn. I did write one pulse out to the 166 as the changed the state of the load/shift line, see Void CIPULSE is towards the end of the code. As the 74HC166 is Synchronous Load register it means you get a picture of all of your input at one moment in time which might be important depending on your project. So as you serial shift the data in it is a look at one moment in time and remains related to the first bits you pulled in no matter how many you hook up.

Yes normally a patch of code as small as CIPULSE would just get put in the mainstream of the code. But remember I was planning a new shiftin routine to match up with the needs of the 166 chip. So figured it would be needing lots of clocking.

On first test everything was looking very good, I had not connected the 74HC595 yet and was just looking at the serial monitor to see what values where coming in from the 74HC166.

The data was missing the Less Significant bit of the byte I was trying to acquire.

This was the bit connected to pin 14 of the 74HC166. I check with a logic probe and the input was there and changing if I moved the switch. I was back to thinking about running a full logic table routine to strobe the 166 and get the data without the use of shiftIn.

I then decided that by removing one line of code from CIPULSE was worth a quick try. So instead of the pulse program starting with the CLOCKI ( Clock for Input) LOW then setting HIGH then back to LOW, I left the line HIGH on exiting the routine. By leaving the clock line to the 166 in this state shiftIn started to work and the data rolls in perfectly.

In the comments at the start of the program you will find what leads I connected to the 74HC166. I basically connected all the control lines. I figured I might need to experiment with all of them to get a good result. Pretty sure you can dump the CLEARI and CLKINH by connecting pin 9 HIGH and pin 6 LOW on the 74HC166.

I then worked out an excel sheet that gives you what switch inputs make useful display outputs on the LED display. I plan to use an array to the display the values being input out to the display with the data from the Excel sheet. Bear in mind that a low on an input lead of the 74HC166 becomes a low on the output of the 74HC595. So the led display has a common positive lead meaning that logic zero turns the LED on. I know that seems to take a flip but it is better to sink current for Leds then to source it. The table deals with this so you get what Hex value to send out to make which ever digit you need to display 0 to F

My next step will be to daisy chain more 74HC166's by connect pin 1 of the first to pin 13 of the second. and repeating for as many chips as needed to get the input needed. The control line will all just run in parallel across the 166 chips and the data will flow out of pin 13 and into pin 1 of the next until it get to the UNO. For each extra chip added a new variable and shiftIn will be added but there will be no need to change any of the control leads after the first shiftIn has been complete just keep reading in bytes until bytes in equals the number of 74HC166's.

The data sheet for the 74HC166 is included here it seems to be the correct version for the chip I am using, different manufactures changed the names of some of the pins. The pins still do the same thing it is just confusing when trying to figure out what to connect where. Also the  with excel table note the Most Significant nibble of the input is the vertical 0 to F column and the Least Significant nibble of the is across the top and bottom rows. Smaller table below shows good results to put in array for display values.

Well that's everything but the kitchen sink. Hope this helps anyone who has a drawer full of 74HC166 chips out there.


Go Up