shiftin with 74hc166 74f166

I've had trouble finding much information about shift in registers. I would appreciate pointers to where i can read up or specific help on my circuit.

The shiftIn() code from the arduino tutorial does not adapt from the shift register it is written for to a 74HC166 or 74F166, and I would blame the datasheets for this chip, not the tutorial.

What is not clear is how the latch/strobe/PE pin is meant to be used. The datasheet is vague, for me at least. Can someone else shed light on this: "When the PE is low one setup time before the low–to–high clock transition, parallel data is entered into the register. When PE is high, data is entered into internal bit position Q0 from serial data input (Ds), and the remaining bits are shifted one place to the right (Q0 [ch8594] Q1 [ch8594] Q2, etc.) with each positive going clock transition."

If I had to guess I would say that they are suggesting that I: - Set PE low to read parallel inputs into buffer - read first bit - Set PE High to allow for shifting - Loop:

  • Clock once shift all right one (shifting in one bit from the serial input, as a side effect)
  • read next bit

Is this the correct understanding? This hasnt worked for me. Another possibility is that I need to use resistors on my inputs? For testing purposes I just plugged each parallel input pin into ground or VCC. I was hoping to see a bit pattern when I shift in but i am only seeing 0's.

many thanks. I would be happy to summarize or writeup a tutorial for these shift registers once i get it working

Set PE low to read parallel inputs into buffer

read first bit not needed.

Set PE High to allow for shifting

Loop:

Another possibility is that I need to use resistors on my inputs?

Yes you do. Connect pull up resistors on all the inputs then connect to ground the ones you want to see as logic zeros.

Set PE low to read parallel inputs into buffer

read first bit not needed.

Set PE High to allow for shifting

Loop:

Do you mean now Loop back to setting PE low again? I assume this means, read bit and then loop. Or, are you implying that I should loop the additional steps I had before (basically read, then clock, read, then clock).

Sorry, just the syntax of the datasheet has twisted my brain so im still in datasheet mode ;)

Set PE low. Set PE high Then toggle the clock and read the data eight times.

okay if I read that correctly ive tried it and now im just getting a one on input 1 for every polling

74F166 wiring:

Ds->gnd
D0->150ohm->VCC
D1->10k->VCC
D2->gnd
D3->gnd
D4->gnd
D5->gnd
D6->gnd
D7->gnd
CE->gnd
CP->Arduino output (labeled CLOCK)
PE->Arduino output (labeled STROBE/latch)
MR->VCC (datasheet: on low reset chip)

The resistor values just happened to be what I have laying around at the time. I'm trying to just get two bits here.

"When the PE is low one setup time before the low–to–high clock transition, parallel data is entered into the register"

Code:

  digitalWrite(CLOCK,0); // 
  delayMicroseconds(20);
  digitalWrite(STROBE,0); 
  // PE now low before low_to_high clock transition
  delayMicroseconds(20);
  digitalWrite(CLOCK,1);
  // high clock has happened so data should be in register
  delayMicroseconds(20);
  digitalWrite(STROBE,1);
  delayMicroseconds(20);
  // reading in always results as 0
  input = digitalRead(DATAIN);
  Serial.println(input, BIN);
  delay(2000);

I guess the only thing that is un clear from the datasheet is When does the IC shift the register?

Okay, if I shift my pull up resistor to D7 I get one on the input read which implies that for the Loop step I just need to pulse the clock once.

I think I got this. Will apply it now and then write up a tutorial in a bit

thanks

that for the Loop step I just need to pulse the clock once.

Yes just clock it once per bit. That is clock high then clock low and then read. Or even clock high, read clock low. The data is transfers or shifted on the rising edge of the clock pulse.

For those interested, I used an HEF4014 in the end. The 74F166N appears to only work at 5v+ from testing and needed the option to use 3.3v. So, with the HEF4014 the wiring i have is:

Data input pins to my parallel inputs of HEF4014. Arduino pins: 10 "DATAIN" to Q7 pin of HEF4014 11 "CLOCK" to CP pin of HEF4014 09 "STROBE" to PE pin of HEF4014

Code:

        //
        // READ INPUT
        //
                digitalWrite(CLOCK,0);
                digitalWrite(STROBE,1);
                digitalWrite(CLOCK,1); // important
                digitalWrite(STROBE,0);

                  for (int i=7; i>=0; i--)
                  {
                    digitalWrite(CLOCK,0);
                    delayMicroseconds(2);
                    input = digitalRead(DATAIN);
                    Serial.print(input, BIN);
                    digitalWrite(CLOCK,1);
                    delayMicroseconds(2);
                  } 
                  Serial.println();

If you wish to chain two or more HEF4014's together you would connect the DS pin (serial input) of the IC that will be closest to the Arduino (the one with the DATA line going to the Arduino) to Q7 of the next HEF. Then in the code change "int i=7" to "int i=15".

The 74F166N appears to only work at 5v+ from testing

It also mentions it in the data sheet.

It also mentions it in the data sheet.

It does indeed, in the recommended specifications but the abs. max says –0.5 to +7.0 so I thought I would test it anyway. When you dont have time to source parts, well when I dont have time, im willing to break something to see if I can get it working.

Datasheets rule!