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!

spdif
  • 53
  • 5
  • PNP on each cathode?! Surely you mean NPN...? You'd use PNP with a common anode, not a common cathode display. – Majenko Sep 13 '20 at 10:11
  • Oh yes... I am sorry. 547 is an NPN. – spdif Sep 13 '20 at 10:36
  • If you only ever display one digit (never increment count) do you still see ghosting on that digit? – Majenko Sep 13 '20 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. – StarCat Sep 13 '20 at 11:06
  • @Majenko Thanx for the effort. It is solved. – spdif Sep 14 '20 at 08:35
  • @StarCat It was a coding error. Its done now. Thanx anyway!! – spdif Sep 14 '20 at 08:36
  • @jsotola I have corrected it. Thanx – spdif Sep 14 '20 at 08:36

1 Answers1

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.

Gerben
  • 11,286
  • 3
  • 20
  • 34
  • Bingo!! It worked. Thank You! – spdif Sep 14 '20 at 08:34
  • Glad it worked. digitalWrite is relatively slow. Thought I've had "ghosting" with direct port manipulation too. – Gerben Sep 14 '20 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. – spdif Sep 20 '20 at 06: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. – Gerben Sep 20 '20 at 14:33
  • Well, I understood the first part (adding a number to the array) and in my case the 7th element would render all digits blank, but unclear on the second part. And specially "number" 10 – spdif Sep 22 '20 at 06:40
  • The numbers array is a lookup table for how to display a certain number (that is; which segments to turn on. Where index 0 gives you the segments that need to be on to show the character "0" on your 7-segment display. Index 1 for character "1" etc. I'd add an index 10 at the end for the empty character. The to set a digit to blank, use something like digits[1]=10;. Why did you numbers array only have 6 elements? I was expecting it to have 10 (indexes 0..9). – Gerben Sep 22 '20 at 15:05
  • You could even add more indexes for the characters "AbCdEF-_" (which are about all the characters you can make on a 7-segment display). – Gerben Sep 22 '20 at 15:05
  • Aahh I got you! Sorry I got confused in digit numbers. Earlier I had 4digits but now they are 6. So, had to add another element in the numbers array....great let me try it. I am making a reverse time counter for a machine. 6 digits mean, H M S . It is working good only I just wanted to blink the digit while setting the countdown time. – spdif Sep 24 '20 at 04:42
  • Ahh, now I get it. Note that you also have a decimal point. You could also use those to indicate a different mode (e.g. "time setting mode"). Just a thought. – Gerben Sep 24 '20 at 15:39
  • 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. – spdif Oct 03 '20 at 08:53