3

I hooked up 4 7Seg leds (CC) with NPN transistors on the cathode of each digit. I am using 74HC595 shift register connected in the circuit in a pretty common fashion. The code I am running is the basic scanning code for the 7seg. The problem is that I see the scanned numbers on other LED digits too. Attached is the image. I call them "ghosts". The circuit I am using has an Atmega328 with an internal 8MHz Osc. The resistors on the segments are 220Ohm and 4 BC547's on the cathodes of the digits with 1kOhm resistors on their base. enter image description here

below is the code:

void loop() {
 
 cathode_high(); // blank the screen
 
 break_number(number);
 
 display_number();
 delay(1);
 
}
void break_number(int num) { // seperate the input number into 4 single digits
 first_digit = num / 1000;
 digits[0] = first_digit; 
 int first_left = num - (first_digit * 1000);
 second_digit = first_left / 100; 
 digits[1] = second_digit;
 int second_left = first_left - (second_digit * 100); 
 third_digit = second_left / 10; 
 digits[2] = third_digit; 
 fourth_digit = second_left - (third_digit * 10);
 digits[3] = fourth_digit;
 
 
}
void display_number() { //scanning
 
 cathode_high(); 
 digitalWrite(latch, LOW); 
 shiftOut(data, clk, LSBFIRST, numbers[digits[count]]); 
 digitalWrite(CAS[count], HIGH); 
 digitalWrite(latch, HIGH); 
 count++; 
 if (count == 4) {
 count = 0;
 }
}
void cathode_high() { //turn off all 4 digit
 digitalWrite(CA_1, LOW);
 digitalWrite(CA_2, LOW);
 digitalWrite(CA_3, LOW);
 digitalWrite(CA_4, LOW);
}

Any help would be highly appreciated. Thanx in advance!

asked Sep 13, 2020 at 9:48
7
  • PNP on each cathode?! Surely you mean NPN...? You'd use PNP with a common anode, not a common cathode display. Commented Sep 13, 2020 at 10:11
  • Oh yes... I am sorry. 547 is an NPN. Commented Sep 13, 2020 at 10:36
  • If you only ever display one digit (never increment count) do you still see ghosting on that digit? Commented Sep 13, 2020 at 10:50
  • Could you measure the voltage on the Cathode pins when they're supposedly turned off? My guess is the BC547's do not completely turn off current through the display, or turn off very slowly, which explains the "ghost" when switching between digits. If you have an oscilloscope you could watch the voltage on the BC547's collector. Commented Sep 13, 2020 at 11:06
  • @Majenko Thanx for the effort. It is solved. Commented Sep 14, 2020 at 8:35

1 Answer 1

4

You change cathodes (digits) before latching in the new data. So for a spit second the data for the previous digits is shown on the current digit.

Swapping digitalWrite(CAS[count], HIGH); and digitalWrite(latch, HIGH); should fix that.

answered Sep 13, 2020 at 13:37
10
  • Bingo!! It worked. Thank You! Commented Sep 14, 2020 at 8:34
  • Glad it worked. digitalWrite is relatively slow. Thought I've had "ghosting" with direct port manipulation too. Commented Sep 14, 2020 at 17:32
  • Is there a way we can turn On/Off a full digit using the scanning method with 74hc595? As far as I understand, we cannot because the display_number() function is switching the digit pins already for scan. Commented Sep 20, 2020 at 6:14
  • I'd add one more element in the numbers array for the "no digit", with all segments off. To turn of a digit, you can then set the digit to the "number" 10. Commented Sep 20, 2020 at 14:33
  • 1
    Hey, Sorry I got stuck somewhere else. I have this on my mind too. Will try and get back. Thanx for all the support again. Commented Oct 3, 2020 at 8:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.