Shift Register Troubles
Terrabite3
Posts: 3
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:
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.
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!
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 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.
Different power supply requirements for the above, different speeds and different thresholds for a logic high. Which one do you have?
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.
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.