Pages: [1]   Go Down
Author Topic: Reversed output on 74hc595  (Read 842 times)
0 Members and 1 Guest are viewing this topic.
Ankara, Turkey
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am a beginner at electronics. I was trying to light up 8 leds using a 74hc595. I did all the cabling and programming but faced a very unexpected result. When I upload a high bit to the register, it outputs a low bit, and vice versa. So when I want to light up all 8 leds, they all get dark. If I try to to get them all dark, then they altogether light up. Here is my code for lighting them up one by one (This actually makes them all dark one by one):

Code:

int pData = 2;
int pShift = 3;
int pLatch = 4;

void setup()
{
  pinMode(pData, OUTPUT);
  pinMode(pShift, OUTPUT);
  pinMode(pLatch, OUTPUT);
}

void loop()
{
 
  digitalWrite(pLatch, LOW);

  digitalWrite(pShift, LOW);
  digitalWrite(pData, HIGH);
  digitalWrite(pShift, HIGH);
 
  digitalWrite(pLatch, HIGH);

  delay(500);
}

I can of course move on with this reverse logic, uploading high when I need low, etc, but seriously, what is going on here? Any guidance is appreciated.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
digitalWrite(pShift, LOW);
  digitalWrite(pData, HIGH);
  digitalWrite(pShift, HIGH);

You have just loaded '1' into the shift register.
Logged

Dallas, TX
Offline Offline
Sr. Member
****
Karma: 10
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like a wiring logic problem. Can you post your schematic?
Logged

Ankara, Turkey
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have a schematic ready but I can show you some pictures:


* IMG_20121205_155108.jpg (117.97 KB, 1200x900 - viewed 19 times.)

* IMG_20121205_155120.jpg (141.27 KB, 1200x1129 - viewed 11 times.)
Logged

Ankara, Turkey
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
digitalWrite(pShift, LOW);
  digitalWrite(pData, HIGH);
  digitalWrite(pShift, HIGH);

You have just loaded '1' into the shift register.


And that is supposed to light up the first led, right? In my case it does the opposite.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Depending how the leds are wired, those pictures can be total correct.

If you don't want to reverse your data being sent, just reverse how the leds are wired: if they are wired to ground now; wire them to Vcc; if they are wired to Vcc, wire them to ground.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
that is supposed to light up the first led, right?

Yes / no, depending on how your leds are wired.
Logged

Ankara, Turkey
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Depending how the leds are wired, those pictures can be total correct.

If you don't want to reverse your data being sent, just reverse how the leds are wired: if they are wired to ground now; wire them to Vcc; if they are wired to Vcc, wire them to ground.


Damn, I totally see your point. thanks a million. I had to be much more careful.
Logged

Dallas, TX
Offline Offline
Sr. Member
****
Karma: 10
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have a schematic ready but I can show you some pictures:


Okay, it appears you have your logic backwards. You have all your LED anodes wired to +V through a current limiting resistor. Then you are driving the individual cathodes from the output of your shift register. So, if you want to turn on an LED you must write a LOW into the shift register output so that current will flow from +V toward a low voltage(effectively ground). When you write a HIGH into the shift register output, you effectively have +V at both ends of your circuit, and no current flows. Does that make sense?
Logged

Ankara, Turkey
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have a schematic ready but I can show you some pictures:


Okay, it appears you have your logic backwards. You have all your LED anodes wired to +V through a current limiting resistor. Then you are driving the individual cathodes from the output of your shift register. So, if you want to turn on an LED you must write a LOW into the shift register output so that current will flow from +V toward a low voltage(effectively ground). When you write a HIGH into the shift register output, you effectively have +V at both ends of your circuit, and no current flows. Does that make sense?

It absolutely does. Thank you very much. Problem solved.
Logged

Dallas, TX
Offline Offline
Sr. Member
****
Karma: 10
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have a schematic ready but I can show you some pictures:


Okay, it appears you have your logic backwards. You have all your LED anodes wired to +V through a current limiting resistor. Then you are driving the individual cathodes from the output of your shift register. So, if you want to turn on an LED you must write a LOW into the shift register output so that current will flow from +V toward a low voltage(effectively ground). When you write a HIGH into the shift register output, you effectively have +V at both ends of your circuit, and no current flows. Does that make sense?

It absolutely does. Thank you very much. Problem solved.

You're welcome. smiley
Logged

Pages: [1]   Go Up
Jump to: