Current limiting resistor for 7-segment

Go To Last Post
24 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have 4 digits and need to supply a maximum of 15mA per segment, where each segment (RED) needs 2.1V. For example, the refresh rate is 220Hz, hence 55Hz/digit. How can I calculate the value of each of the 8 resistors that will allow me to pass 15mA to each segment during the time the segment is lit?

I am asking this because I have a lot of 82R resistors and I wanted to use them, what is the safe refresh rate that will yield 15mA/segment consumption. Vcc is 5V, of course.

Necessary part of the code is shown for reference

//common anode or common cathode
//this will save 2 bytes, no need to use
//bitwise NOT operation later on
//1 --> common anode
//0 --> common cathode
#define CA	1

volatile unsigned int val = 0;

#if CA
unsigned char digits[] = {
	~(SEG_a|SEG_b|SEG_c|SEG_d|SEG_e|SEG_f),			// 0
	~(SEG_b|SEG_c),									// 1
	~(SEG_a|SEG_b|SEG_d|SEG_e|SEG_g),				// 2
	~(SEG_a|SEG_b|SEG_c|SEG_d|SEG_g),				// 3
	~(SEG_b|SEG_c|SEG_c|SEG_f|SEG_g),				// 4
	~(SEG_a|SEG_c|SEG_d|SEG_f|SEG_g),				// 5
	~(SEG_a|SEG_c|SEG_d|SEG_e|SEG_f|SEG_g),			// 6
	~(SEG_a|SEG_b|SEG_c),							// 7
	~(SEG_a|SEG_b|SEG_c|SEG_d|SEG_e|SEG_f|SEG_g),	// 8
	~(SEG_a|SEG_b|SEG_c|SEG_d|SEG_f|SEG_g),			// 9
};
#else
unsigned char digits[] = {
	(SEG_a|SEG_b|SEG_c|SEG_d|SEG_e|SEG_f),			// 0
	(SEG_b|SEG_c),									// 1
	(SEG_a|SEG_b|SEG_d|SEG_e|SEG_g),				// 2
	(SEG_a|SEG_b|SEG_c|SEG_d|SEG_g),				// 3
	(SEG_b|SEG_c|SEG_c|SEG_f|SEG_g),				// 4
	(SEG_a|SEG_c|SEG_d|SEG_f|SEG_g),				// 5
	(SEG_a|SEG_c|SEG_d|SEG_e|SEG_f|SEG_g),			// 6
	(SEG_a|SEG_b|SEG_c),							// 7
	(SEG_a|SEG_b|SEG_c|SEG_d|SEG_e|SEG_f|SEG_g),	// 8
	(SEG_a|SEG_b|SEG_c|SEG_d|SEG_f|SEG_g),			// 9
};
#endif

ISR(TIMER0_COMP_vect) 
{ 		
	//turn off all digits
	CA_PORT &= 0xF0;
	
	unsigned char cnt = 0;
	if ( val == 0) cnt = 1;
	
	static unsigned char active_digit = 0; 
	unsigned char digit_val[4] = {0, 0, 0, 0}; // NUMBER OF DIGITS
	unsigned int tmp;
	
	//extract each digit's value
	tmp = val;	// necessary to prevent modifying val variable
     while (tmp > 0)
	{
		digit_val[cnt++] = tmp % 10;
		tmp /= 10;
   }	
   /*
   Leading zeros suppresion
	cnt from above calculation can tell us how many
	digits should be lit without using if statement
   */
	active_digit = ++active_digit % cnt;
	SEGMENT_PORT = digits[digit_val[ active_digit]];

	//turn corresponding digit on
	CA_PORT |= (0x01 << active_digit);

};

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The refresh rate is not relevant to current. Refresh rate WILL affect whether there is flicker. And the percentage ON-time will affect the apparent brightness.

If your supply is 5V and you have 2.1V across each segment at 15ma, then the current limit resistor has a voltage drop of 5V - 2.1V = 2.9V.

By ohms law, 2.9V and 15ma happens with a resistor of 193 ohms. 200 ohms would be close enough.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I thought refresh rate had something to do with the actual average current passing through each segment, while waiting for the answer, I ran the 4 digits with 82R resistors and 250Hz refresh rate, does this mean, I shortened the display and AVR chip life :?

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With 82R resistors, your peak current will be 2.9V/82 = 35ma.

I have not read your code carefully, but if you are multiplexing on a character basis (segement 1 of 1st character is on, then segment 2 of 2nd character, etc), then each segment is on 25% of the time and the average is 35ma/4 = 9ma.

Whether or not the peak current vs average is bad for the LED depends on what the spec sheet says. As for the AVR, if a port-pin is supplying the segment current, the spec sheet says 20mA maximum (for most AVRs). There is no qualification of peak or average. Thus, the general interpretation is "do not exceed., period". It is possible that the device lifetime could be compromised if you run this for a long time. Little probable damage for short experiments. You would be safe if you put two 82R in series though the segments will be pretty dim.

It won't be as bad as you might expect, however, on brightness. That is because, with the high current, your pin output voltage is pretty low and you are getting nothing like 5V out. Doubling the series resistance will actually give you higher drive voltage so the brightness will not be halved.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got your point, thank you.

Edit: I could not notice differences in brightness between 82R and 164R.

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

Last Edited: Thu. Sep 6, 2012 - 06:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I have 4 digits and need to supply a maximum of 15mA per segment, where each segment (RED) needs 2.1V. For example, the refresh rate is 220Hz, hence 55Hz/digit. How can I calculate the value of each of the 8 resistors that will allow me to pass 15mA to each segment during the time the segment is lit?

You normally multiplex by lighting one digit at a time. So 82R gives peak 35mA per segment. With four digits, this is an average current of 9mA over the full period.

This will be serious over current if you are displaying "8.8.8.8.". i.e. a constant 280mA for the 8 segment pins.

The most serious problem is the current to the common pin of each digit. You must use an external driver at these currents.

Be realistic. Light one segment by hand with different resistors. I would guess that 1mA will give you a readable display.
This implies:
segment current: average=1mA peak=4mA
max common 'digit' current: average=8mA peak=32mA

At these currents, you can drive your display with regular GPIO pins. And gives segment resistors of 720R.

In simple terms, you can drive a display for indoor use with just GPIO.
For a 'brighter' display, drive segments with GPIO, digits with transistors.
For an 'outside' display, drive both segments and digits with external chips.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you David, what chips would you suggest to be used in the case of 'outside' display?

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The MAX7219 family comes to mind.

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think I can use ULN2803, it is a cheaper option.

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why don't you just go with 4 cheap universal transistors in the common anode lines then?

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are right, ULN2803 won't be necessary then.

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

There is something strange, what is the explanation of different brightness when using NPN and PNP transistors? Digits with NPN are brighter than with PNP transistors. Before I buy BC557 PNP transistors, I was using 2N2222 NPN transistors. Today I got the BC557 and I just replaced the 2N2222, to my surprise, they resulted in much less brightness than they used to be with 2N2222. I had to lower the base resistor of the PNP transistors in order to get higher brightness, still I could use base resistors as high as 10K with the NPN transistors without noticing any brightness changes, what is the reason for that? I need to understand why this happened and which transistors should I use with a common-anode display? How should I then calculate the base resistors for both cases?

thanks

Attachment(s): 

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When you use a common collector configuration, the voltage gain is less than one. In other words you need to have base voltage of at least 5.6 Volt on the base to even turn the transistor on.
With the PNP, the transistor is operating in common-emitter configuration. The base voltage only needs to be 0.6 Volt.

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your PNP circuit is correct. Everything is "active-low". i.e. enable digit/segment when port pin is 0.

How your NPN circuit works is a mystery. The digits will be "active-high". You will struggle to saturate the NPN.

If you used a Common-cathode display, you use NPN for digits (or ULN2803). Digit will be active-high. Segments will be active-high.

An AVR is quite happy with CA or CC displays. A traditional 8051 will only use a CA display.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, the NPN circuit is active high. Both work, but the strange thing is that the PNP needs much lower base resistor. I also noticed in NPN circuit that when vcc is disconnected from the collector, the digit work, but are very dimmed, seems like the diode junction works in this case.

It is not a code problem, I need to understand why this happens. Why is the NPN circuit is giving better results at the shown components values than PNP? Also, why do I have to lower the base resistors to 1K to get decent brightness?

P.S. I also noticed that the switching speed of the NPN is faster than the PNP.

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With the NPN configuration, it is the current from the I/O line, through the base resistor and the base-emitter circuit that is driving the LED.
The transistor is not being really turned on and therefore disconnecting the collector from Vcc makes no difference.

I see the mistake being made quite often.

To utilize digital electronics, you need to have a good grasp of analog electronics.

Get a copy of The Art of electronics by Horowitz & Hill.

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No need, I came here asking because what was going on is against what I have been taught years earlier. Sometimes man forgets and things confuse in the brain : )

Any way, I found the error:
In eagle, the pins of emitter and collector of BC557 are reversed, this is a fatal error IMO. I looked at the datasheets and in eagle they are exactly the opposite. Display is really bright now, brighter than the NPN variant and with 1K base resistors!

The funny thing is that I sent the PCB files to the manufacturer today, luckily, he told me I have till Thursday if something wrong appears in the files, as if has already known it is :idea:

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

Last Edited: Mon. Sep 10, 2012 - 10:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can never understand why people use the 2N2222. It has a min hFE of 75.
The BC557 has min hFE of -125.

General purpose transistors are pretty cheap. You might just as well use models with better hFE.

The BC557 base resistor is fine at 4k7. 10k would be fine too. 1k is overkill.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
There is something strange, what is the explanation of different brightness when using NPN and PNP transistors? Digits with NPN are brighter than with PNP transistors.
It should be other way round, because there is a drop 0.7 V on NPN.

I did a quick test. See the picture.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you are wondering why/how the NPN configuration works, it is high-side an emitter follower. It lights the LED when IO pin is high.

The PNP configuration is a high-side switch, which lights the led when IO pin is low.

So IO pins must be driven in different directions with different transistor.

If no software is changed, then the emitter follower keeps three digits on at the same time and only one off at a time, so a digit appears brighter.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
I can never understand why people use the 2N2222. It has a min hFE of 75.
The BC557 has min hFE of -125.

The difference is if you need to drive up to 100mA loads with BC557 or up to 500mA loads with 2N2222.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes. But you can find several 500mA NPNs with a better hFE.

Choosing a 'general purpose' NPN or PNP is not difficult.
e.g. Ic from 1mA to 500mA. typical hFE > 200 (min > 100)

When people use transistors with min hFE of 25 or 30, I really wonder. 99% of the time you do rule-of-thumb calculations. With 'low-hFE' devices, the worst case calculations need some work!

Of course there are always special cases. e.g. power, voltage, speed, package, price, ...
In which case you choose a 'special' device.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jepael wrote:
If you are wondering why/how the NPN configuration works, it is high-side an emitter follower. It lights the LED when IO pin is high.

The PNP configuration is a high-side switch, which lights the led when IO pin is low.

So IO pins must be driven in different directions with different transistor.

If no software is changed, then the emitter follower keeps three digits on at the same time and only one off at a time, so a digit appears brighter.

I understand how the NPN configuration works, and I can assure you is that for the same display, using PNP makes them brighter, because the NPN circuitry works in emitter follower configuration. The funny thing is that when I was watching the PNP reversed and wondering why the digits were not bright : )

I don't understand how this one worked, but when I decreased the base resistor value, it became a bit brighter. May be in some reversed mode, I am not sure.

Attachment(s): 

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, I have not updated my memory on this.

A regular PNP transistor can have its collector and emitter transposed. The resultant is still a PNP. However the hFE will be crap. The saturation voltage will be crap. The 'allowable' voltages will be crap. Think about it. Most base-emitter reverse breakdown voltages are about 6V. So this now means that the voltage between 'collector' and base is going to be very limited.

Of course, with a 5V VCC, your transistor will not encounter any breakdown voltages. It will just look like a PNP with an hFE of 5-10.

Do the sums with your circuit values. The reversed 'PNP' will never saturate.

The same argument applies to swapping the Ns of a NPN transistor.

David.

p.s. having typed this message without any research, I thought I should test the theory.
I placed a BCY70 transistor in the hFE socket of my £5 DMM.
The correct way round: hFE = 95
With emitter, collector swapped: hFE = 2

The BCY70 has a min hFE of 50. Incidentally, VEBO is -5V for this transistor.