Shop OBEX P1 Docs P2 Docs Learn Events
Shift Register Troubles — Parallax Forums

Shift Register Troubles

Terrabite3Terrabite3 Posts: 3
edited 2010-08-17 10:53 in Propeller 1
I'm interfacing with a 74164 shift register, but it is proving difficult. The shift register is driving 8 LEDs right now, making it very easy to detect issues. The patterns %11111111 and %00000000 always work fine, but more complex ones, like %10101010 are corrupted, but always in the same way. In other words, a given pattern always activates the same set of LEDs, but they aren't the correct LEDs.

The most likely source of error is my Shift method:
PUB Shift (the_number)
  repeat 8
    outa[DATA] := (the_number & 1)  
    outa[CLK] := 1        
    outa[CLK] := 0       
    the_number >>= 1

I believe this is the bad code, because I ported the program to Arduino line-by-line. The only thing I changed was the method of extracting the bits from the byte. For reference, here are both versions of the program. The red, green, and blue are for switching between cathodes for the three colors on the RGB LEDs. The Arduino version works flawlessly.
PUB Main
  dira[DATA]~~
  dira[REDPIN]~~
  dira[GREENPIN]~~
  dira[BLUEPIN]~~
  dira[CLK]~~
  Shift(%10101010)
  repeat        
    Red
    waitcnt(3_000_000 + cnt)
    Green
    waitcnt(3_000_000 + cnt)
    Blue
    waitcnt(3_000_000 + cnt) 
  
PUB Shift (the_number)
  repeat 8
    outa[DATA] := (the_number & 1)  
    outa[CLK] := 1        
    outa[CLK] := 0       
    the_number >>= 1  

PUB Red  
  outa[REDPIN..BLUEPIN] := %100 

PUB Green         
  outa[REDPIN..BLUEPIN] := %010  

PUB Blue             
  outa[REDPIN..BLUEPIN] := %001

CON
  CLK   =       27
  DATA  =       0
  REDPIN   =       24
  GREENPIN =       25
  BLUEPIN  =       26
byte  CLK   =       11;
byte  DATA  =       2;
byte  REDPIN   =       8;
byte  GREENPIN =       9;
byte  BLUEPIN  =       10;
  
void setup() {
  pinMode(DATA, OUTPUT);
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  pinMode(CLK, OUTPUT);
  Shift(B10101010);  
}  

void loop() { 
    Red();
    delay(300);
    Green();
    delay(300);
    Blue();
    delay(300);
}
  
void Shift (byte the_number) {
  for (int i = 0; i < 8; i++) {
    digitalWrite(DATA, bitRead(the_number, 0));  
    digitalWrite(CLK, HIGH);        
    digitalWrite(CLK, LOW);       
    the_number = the_number >> 1;
  }
}

void Red () {  
  digitalWrite(GREENPIN, LOW);
  digitalWrite(BLUEPIN, LOW);
  digitalWrite(REDPIN, HIGH);
}

void Green () {  
  digitalWrite(BLUEPIN, LOW);
  digitalWrite(REDPIN, LOW);
  digitalWrite(GREENPIN, HIGH);
}

void Blue () {  
  digitalWrite(GREENPIN, LOW);
  digitalWrite(REDPIN, LOW);
  digitalWrite(BLUEPIN, HIGH);
}

Curiously, when using the SPI_Asm library, I get similarly incorrect results. I have not verified that they are the exact same results, though. Any help is greatly appreciated. I would hate to leave the Propeller because I couldn't get a shift register to work!

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-08-15 10:08
    I don't see anything wrong with code. May need to check wiring. Are master reset and the other input line tied high? Are you running the chip at 5 volts?

    John Abshier
  • Terrabite3Terrabite3 Posts: 3
    edited 2010-08-15 20:34
    I don't see anything wrong with code. May need to check wiring. Are master reset and the other input line tied high? Are you running the chip at 5 volts?

    John Abshier

    I've double-, triple-, quadruple- checked the pinout and everything seems to be hooked up properly. Besides, the Arduino talked to it just fine. So what wiring issues could cause it to work with one µC and not another?

    Now there is something that could be problematic. I am running the Prop from 3.3V, but the 74164 (and the Arduino) are at 5V. But the input threshold should be 2.1V to 2.4V, plenty of room from 3.3V. (Well, that's for 4.5V supply, so increase those both a bit more.)

    I can try powering the shift register from 3.3V, but that isn't a permanent solution; I've already soldered my current limit resistors for 5V.

    Thanks for the help.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-08-15 21:56
    You do have a decoupling cap on the 74164 right? 0.1uF or so. The lower voltage should be ok on the inputs of the 74164, but might make a difference as far as their reaction time (might be slower). A decoupling cap should help. You can also try to insert a delay when you clock the signal HIGH and then back LOW. That said, with Spin though it should have plenty of delay already built in. The PAsm version however might have issues, but even then the 74ACT164 should be good up towards 100MHz. What are the 'xx' prefix letters on your 74xx164?
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-08-15 22:32
    74164, 74HC164, 74HCT164 74LS164, 74ACT164, 74F164 ?

    Different power supply requirements for the above, different speeds and different thresholds for a logic high. Which one do you have?
  • Terrabite3Terrabite3 Posts: 3
    edited 2010-08-17 00:20
    I tried powering the 74164 from 3.3V, and it worked great. So why is it working improperly and how can I fix it? (Besides running the 74164 at 3.3V.)

    The decoupling cap didn't make any difference, but I'll build it into my design from here forward anyways.

    I'm using HC; they were cheapest and met my requirements.

    Thanks, all.
  • LeonLeon Posts: 7,620
    edited 2010-08-17 00:29
    The logic thresholds are wrong if it is powered from 5V and you are driving it from a 3.3 V Propeller. Check the HC logic specifications.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-08-17 10:53
    Looking at the data sheet here on page 2 it gives a logic HIGH threshold between 2.4V and 3.15V when the 74HC is powered from a 4.5V supply. This threshold increases to 3.2V and 4.2V with a 6V supply. If you take the linear derivative between these two data points, the threshold at 5V is about 2.7V to 3.6V which is probably why the propeller can't drive the 74HC164 properly.

    A few options:

    1) Use a 74xx164 chip that can function with 3.3 logic levels

    2) You need to lower the voltage supplied to the 74HC164

    3) use a voltage level translator from an IC or discrete components.

    4) Raise the ground level that the prop runs from by one or two diode drops.
Sign In or Register to comment.