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!

7
  • 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 8:35
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.

10
  • Bingo!! It worked. Thank You! – spdif Sep 14 '20 at 8: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 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. – Gerben Sep 20 '20 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. – spdif Oct 3 '20 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.