Pages: [1]   Go Down
Author Topic: Trouble shooting TPIC6B595N  (Read 798 times)
0 Members and 1 Guest are viewing this topic.
Estonia
Offline Offline
Full Member
***
Karma: 1
Posts: 188
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Edit: I must preface this by saying that I am very very new to these things and have never used a shift register before. I am just trying to get a basic situation working so I can study it further to understand what I am doing.

I am trying to get 8 LEDs to be controlled through the shift register TPIC6B595N, datasheet here:
www.sparkfun.com/datasheets/IC/TPIC6B595.pdf

My problem is that I can't get any lights to light up at all.

I have tried following the tutorials and posts here and here:
http://flashgamer.com/arduino/comments/arduino-controlling-24-leds-with-shift-registers
http://arduino.cc/forum/index.php?topic=50529.0

I have attached the Fritzing file and PNG of my project. Sorry, the red box represents the shift register with the notch on the casing being on the far left side (I couldn't figure out how to create your own component). The oddly placed LED is just there to show that the board is powered and working at a minimal level.

I have tried all of the source code on both of the tutorials / posts to no avail. All lights always stay turned off. To show where I left off trying, my code is as follows at the moment:
Code:
/*
 Shift Register Example
 for TPIC6B595 shift register by Jens C Brynildsen

 This sketch turns reads serial input and uses it to set the pins
 of a TPIC6B595 shift register.

 Hardware:
 * TPIC6B595 shift register attached to pins 7, 8, 11 and 12 of the Arduino,
 as detailed below.
 * LEDs attached to each of the outputs of the shift register

 Based on the example created 23 Mar 2010 by Tom Igoe

10 = register clock / latch pin (RCK)
11 = shift register clear (SRCLR)
8 = serial in (SER IN)
5 = shift register clock(SRCK)
 */

//Pin to clear the register
//const int clearPin = 7;
const int clearPin = 10;
//Pin connected to latch pin (ST_CP) of 74HC595
//const int latchPin = 8;
const int latchPin = 11;
//Pin connected to clock pin (SH_CP) of 74HC595
//const int clockPin = 12;
const int clockPin = 5;
////Pin connected to Data in (DS) of 74HC595
//const int dataPin = 11;
const int dataPin = 8;

int counter = 0;
int numLedsInUse = 24;

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(clearPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("*");
  
  // delay a little and then set
  delay(10);
  // Always start by sentting SRCLR high
  digitalWrite( clearPin, HIGH);
}

void loop() {
  // Display LED's running
  if( counter >= (numLedsInUse-1) ){
    counter = 0;
  } else {
    counter++;
  }
  
  // write to the shift register with the correct bit set high:
  registerWrite(counter, HIGH);
  delay( 10 );
}

// This method sends bits to the shift register:

void registerWrite(int whichPin, int whichState) {
  // the bits you want to send
  byte bitsToSend0 = 0;
  byte bitsToSend1 = 0;
  byte bitsToSend2 = 0;

  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin, LOW);
  
  // Set bit pattern
  bitWrite(bitsToSend0, whichPin, whichState);
  if( whichPin > 7 ){
    bitWrite(bitsToSend1, whichPin-8, whichState);
  }
  if( whichPin > 15 ){
    bitWrite(bitsToSend2, whichPin-16, whichState);
  }
  
  // shift the bits out for all three registers. Note the opposite order.
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend2);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend1);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend0);

  // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);

  
  // debug output
  Serial.print( counter );
  Serial.print( " - " );
  Serial.print( " bitsToSend0 " );
  Serial.print( bitsToSend0, BIN );
  Serial.print( " bitsToSend1 " );
  Serial.print( bitsToSend1, BIN );
  Serial.print( " bitsToSend2 " );
  Serial.println( bitsToSend2, BIN );
  
}

* shift-register.fzz (9.38 KB - downloaded 9 times.)

* shift-register_bb.png (300.86 KB, 878x669 - viewed 39 times.)
« Last Edit: February 22, 2013, 07:27:21 pm by shiznatix » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27353
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This shifts out 3 bytes, if you only have 1 shift register the first 2 bytes will never be seen:

  // shift the bits out for all three registers. Note the opposite order.
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend2);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend1);
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend0);

  // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);

Do you have Master Clear pulled High, and OE/ connected to Gnd, or have PWM for controlling brightness?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 497
Posts: 19047
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

My own 595 tutorial / example:

http://www.gammon.com.au/forum/?id=11518

I don't see where you have Vcc connected to the chip.
Logged


Estonia
Offline Offline
Full Member
***
Karma: 1
Posts: 188
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Final edit: It seams that the issue was that the shift register wasn't sitting properly in the breadboard. If I hold it down into the board with my fingers then it works perfectly. Super annoying but yep, thats it. Thanks for the help and if anyone knows of a way to keep these in the board better that would be great!

The working code is here:
Code:
/*
 Shift Register Example
 for TPIC6B595 shift register by Jens C Brynildsen

 This sketch turns reads serial input and uses it to set the pins
 of a TPIC6B595 shift register.

 Hardware:
 * TPIC6B595 shift register attached to pins 7, 8, 11 and 12 of the Arduino,
 as detailed below.
 * LEDs attached to each of the outputs of the shift register

 Based on the example created 23 Mar 2010 by Tom Igoe

10 = register clock / latch pin (RCK)
11 = shift register clear (SRCLR)
8 = serial in (SER IN)
5 = shift register clock(SRCK)
 */

//Pin to clear the register
const int clearPin = 11;
//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 10;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 5;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 8;

int counter = 0;
int numLedsInUse = 8;

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(clearPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("*");
  
  // delay a little and then set
  delay(100);
  // Always start by sentting SRCLR high
  digitalWrite( clearPin, HIGH);
}

void loop() {
  // Display LED's running
  if( counter >= (numLedsInUse-1) ){
    counter = 0;
  } else {
    counter++;
  }
  
  // write to the shift register with the correct bit set high:
  Serial.print("counter: ");
  Serial.println(counter);
  registerWrite(counter, HIGH);
  delay( 500 );
}

// This method sends bits to the shift register:

void registerWrite(int whichPin, int whichState) {
  // the bits you want to send
  byte bitsToSend0 = 0;
  // write number as bits
  bitWrite(bitsToSend0, whichPin, whichState);

  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin, LOW);
  
  // shift the bits out
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend0);

  // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);
}

@Nick Gammon - I dont see in your tutorial the basic code for just 1 shift register to light up 1 LED at a time. I fixed the problem with not having the Acc connected, very very silly of me.
« Last Edit: February 23, 2013, 11:26:24 am by shiznatix » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 497
Posts: 19047
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The nature of shift registers if you have to send 8 bits at once (or more if you connect multiple 595s). So to turn on one LED you have to shift out 8 bits.

As an example:

Code:
  digitalWrite (LATCH, LOW);
  SPI.transfer (0b00000001);    // turn on one LED
  digitalWrite (LATCH, HIGH);

  delay (1000);

  digitalWrite (LATCH, LOW);
  SPI.transfer (0b00000011);    // turn on a second one
  digitalWrite (LATCH, HIGH);

The second transfer turns on another LED but it also has to send out again the first one.
Logged


Pages: [1]   Go Up
Jump to: