4
\$\begingroup\$

I am a novice and have a problem with my seven-segment display setup.

Basic requirements: I need to control two seven-segment displays with buttons, without multiplexing, with the physically smallest setup and battery setup possible.

My setup: I am using an ATTiny2313 to directly control the seven-segment displays (one IO pin per segment (14x), and two IO pins for buttons), all powered by two AAA L92 batteries.

The good: This works perfectly on my breadboard if I do not use any resistors at all. The displays are bright and the code works perfectly. However, I am not comfortable with this setup, since the segment displays (common anode, Vf=2V, If=20mA) sometimes exceed 20mA per segment, depending on the number of active segments (when displaying the number “11”, my multimeter shows close to 25mA).

The bad: The moment I add resistors for each segment, the brightness drops massively and the displays sometimes even flicker. I started with 68 Ohm resistors (R = 3.3V-2V / 0.02A = 65 Ohm), but began using lower resistors, I’m at 22 Ohm now and it still is abysmal. The multimeter shows about 5-7 mA per segment. The resistors are placed between the individual cathodes and the ATTiny2313.

My goal is to lower the current per segment to just below 20mA. What is the problem here? At first, I thought it might be the battery, but seeing that it works just fine without the resistors, I’m not so sure. Then I thought that maybe the current per IO pin might be too high, but should that really be a problem when it works fine without the resistors? I’m hesitant to buy even lower resistors, since 22 Ohm seems to be practically nothing...

Any input on what I could try or what I’m missing here would be greatly appreciated!

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Xhiwar, Is there a reason you don't want to use an IC? There are lots of them now designed for this kind of purpose and they handle all the intimate details. Some provide feedback about segments that no longer work properly or if they are shorted out, as well. Pretty sophisticated devices for not much money. It can be kind of boutique, though. But you will otherwise need to add active devices, externally. Can't be avoided. Each segment should have its own active current source/sink and, if multiplexing only, the common side should be an active switch (otherwise directly connected to a rail.) \$\endgroup\$ Apr 7 at 20:50
  • \$\begingroup\$ Thanks for your input. Could you elaborate on this please? What kind of IC would you suggest? As stated, I do not have any prerequisites for the display other than 1. I must use my two single digit seven-segment displays (common anode, Vf=2V, If=20mA), 2. It must be battery-powered and 3. No Multiplexing. I'm open to any suggestions on how to best achieve this, if there is an IC that could help me achieve this, I would most certainly look into this. \$\endgroup\$
    – Xhiwar
    Apr 9 at 6:28
  • \$\begingroup\$ @periblepsis I've been trying to read up on this, are you talking about constant current LED drivers? As far as I could gather, these would allow me to drive the segments with a higher current since the individual pins of those ICs will be able to sink more current. However, it is hard to find "newer" ICs that I could use for two segment displays, what would be your suggestion? \$\endgroup\$
    – Xhiwar
    Apr 17 at 18:49
  • \$\begingroup\$ Well, most of the ICs include a lot more than you need to have, such as serial I/O to communicate with the IC, especially when you just want to use the same code as before. When considering current control, you can use discretes for testing some ideas and then implement the final situation using arrays of BJTs, which come in various packaged forms and will require much less space. Are you truly stuck on the idea of keeping your code the same? And would you like consistent current? (Resistors make terrible current control devices but may be acceptable.) \$\endgroup\$ Apr 17 at 20:33
  • \$\begingroup\$ If I were doing this display project and if my standards were high (in terms of having a high quality, uniform appearing, high visibility display), then I'd sit down and design a test setup to implement and a procedure to use, along with the best I could write out about what goals I had in terms of brightness variation between segments. If I were doing this kind of high quality, I may need to adjust the current differently or use PWM within software to adjust for uniformity and there may be a need for a bezel of some kind, too. Or, I may at least need to eliminate that from consideration. \$\endgroup\$ Apr 17 at 21:11

3 Answers 3

8
\$\begingroup\$

The problem that you are experiencing is that the GPIO of your microcontroller(uC) ATTiny2313 can not sink/source the current needed.

I think that a more apropiate way of seeing this problem is bad signal conditioning, this means that the signal output from the previous stage (uC output) is probably not appropiate to drive the next stage (in this case it is the leds).

As you have found out, microcontrollers usually have weak sink/source capabilities on their GPIOs. This means that usually there are intermediate steps/processes/hardware between the uC and the load.

If this was not the case imagine a single uC driving a lightbulb or a DC Motor.

So I'll explain how you could use two different devices in order to achieve what you are looking for:

Bipolar Junction Transistors (BJT)

In this case you can think of the bjt as a current controlled switch, in the specific case of NPN transistor you can expect that if you make some amount of current flow through the base to the emmiter a larger current will flow from the collector to the emmiter, a deeper explanation of these I think is offtopic, as you can do a more in depth investigation on the web.

enter image description here

Metal Oxide Semiconductor Field Effect Transistor (MOSFET) Mosfets are simillar to bjts in this aplication in the sense that they can work as voltage controlled switches, again a deeper explanation of these I think is offtopic, as you can do a more in depth investigation on the web. Below is a simple diagram showing a mosfet driving a light bulb.

enter image description here

To recap it is important that the current driving the leds does not comes from the uC, It needs to come from the Power Supply. So in order to achieve this, you use a power stage (BJT or MOSFET).

The biggest advantages of using mosfets instead of BJT's is that they dont draw current from the GPIO and also that they can switch at much higher frequencies than BJT's. This is a good advantage if you are going to use PWM control to dim the LEDS.

If you are going to use MOSFETS you culd try 2n7000 300 mA n-channel mosfets. If you are using BJT's you could try a 2n2222 800 mA NPN.

\$\endgroup\$
5
  • \$\begingroup\$ While I agree with the idea of using driver transistors, I would not buy them as discrete transistors. Getting them packaged into an IC is substantially less expensive. For only one of many examples: ti.com/lit/ds/symlink/tlc59213.pdf. Admittedly, it's kind of overkill, but at the same time, roughly a quarter the price of discrete transistors. \$\endgroup\$ Apr 8 at 20:18
  • \$\begingroup\$ @JerryCoffin I agree that packaged bundles are almost always cheaper, I pointed out discrete transistors in case the op wanted to do a an isolated test and familiarize with those tecnologies. \$\endgroup\$ Apr 8 at 20:46
  • \$\begingroup\$ Fair enough--certainly not a bad idea to do it with discrete parts a couple of times to help understand what you're dealing with. \$\endgroup\$ Apr 8 at 22:34
  • \$\begingroup\$ Thanks for all your input. I do know what a MOSFET is, but was of the impression (as your answer says) that this was used to drive high-power electronics, and thought that no MOSFET would be necessary to use in a seven-segment display application. Guess I was wrong, I will look into this. Thank you. \$\endgroup\$
    – Xhiwar
    Apr 9 at 6:19
  • \$\begingroup\$ @Xhiwar mosfets as transistors come with all kind of specs. I sure you can find one that can fit your application, I think the most important parameters are Vgs, Id and Rds_on, good luck! \$\endgroup\$ Apr 11 at 0:00
7
\$\begingroup\$

It is unclear what the problem is or isn't, but you are living dangerously.

First of all, if you are using two batteries, the supply is not 3.3V and it is not constant.

Second is that even if you have 20mA per LED, and you have 14 LEDs, you are exceeding the absolute maximum ratings of the MCU, so you can't use 20mA per LED.

If you read the MCU data sheet, IO port total sum of current should not exceed 60mA.

So if you want to display digits "88" you are limited to about 4mA per LED, and that's the brightest you can possibly get while the system is not on the edge of not working due to exceeding safe operating limits.

You must use resistors, or you damage the MCU.

The other problem of not using resistors or trying to push too much current through the MCU is that the supply voltage may drop too much and the MCU needs certain supply voltage to run properly at the speed you set it, and it may fail to work properly for this reason too.

One option to control the LED current better would be to use three batteries and higher resistor values.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for your input. With two L92 (Lithium) batteries, I get a peak current of almost exactly 3.3V. It then drops of course, but I thought I would calculate my resistors based on the maximum current going through the segments. Based on your suggestion, using three batteries and higher resistor values would not solve the problem, I guess I will have to use a MOSFET (perhaps combined with an additional battery). Thank you for your help. \$\endgroup\$
    – Xhiwar
    Apr 9 at 6:23
3
\$\begingroup\$

The datasheet provides this:

enter image description here

From which you can extract these worst-case simplifying I/O pin Thevenin models:

$$\begin{align*} R_{_\text{OL}}=\frac{700\:\text{mV}}{20\:\text{mA}}&=35\:\Omega & @V_{_\text{CC}}=5\:\text{V} \\\\ =\frac{500\:\text{mV}}{10\:\text{mA}}&=50\:\Omega & @V_{_\text{CC}}=3\:\text{V} \\\\ R_{_\text{OH}}=\frac{5\:\text{V}-4.2\:\text{V}}{20\:\text{mA}}&=40\:\Omega & @V_{_\text{CC}}=5\:\text{V} \\\\ =\frac{3\:\text{V}-2.5\:\text{V}}{10\:\text{mA}}&=50\:\Omega & @V_{_\text{CC}}=3\:\text{V} \end{align*}$$

You are at \$3.3\:\text{V}\$ so use the \$3\:\text{V}\$ derived values, above.

Those are worst-case. But that is what you need to design for.

When you added a \$68\:\Omega\$ resistor in series, and assuming that you ignore the fact that the specification says \$10\:\text{mA}\$ and not \$20\:\text{mA}\$ for \$V_{_\text{CC}}=3\:\text{V}\$, you got perhaps \$\frac{3.3\:\text{V}-2\:\text{V}}{50\:\Omega+68\:\Omega}\approx 11\:\text{mA}\$. I used the worst case for this, but that is the worst case for \$10\:\text{mA}\$ and the datasheet is silent on how that output looks when trying to source or sink \$20\:\text{mA}\$ and using your \$V_{_\text{CC}}=3.3\:\text{V}\$.

Also, there's these added notes and specifications:

enter image description here

enter image description here

All of this tells you that you need active devices to provide external discrete (or IC) support.

Learn to read the datasheet!

Since you have 14 segments to drive, this means that you probably should not exceed \$\frac{60\:\text{mA}}{14} \approx 4.3\:\text{mA}\$ and (in my opinion) shouldn't exceed about half that much, or \$2.1\:\text{mA}\$ per I/O pin. This is just enough for the recombination base current of a BJT used as a switch with a collector current of \$20\:\text{mA}\$. (A low logic-level NFET would be better, if also more expensive and perhaps less widely available around the world.)

Resistors make terrible current-source/sink devices when you only have about a volt of overhead to waste on them. Variations in the LED voltage can have significant impact on the LED current in these cases. But you may be stuck with that problem. There are low-voltage-overhead current sink/source designs you can also use with this small margin. But they take a few more parts per segment, too, which takes space and costs money. (There are really good ICs for this, though.)

\$\endgroup\$
8
  • 1
    \$\begingroup\$ Those are not facts, those are just simplifications from the logic level comptibility parametes. The real curves of IO pin voltage vs current are later in the data sheet. However for first order assumption they work quite well. \$\endgroup\$
    – Justme
    Apr 7 at 22:31
  • \$\begingroup\$ @Justme I was trying to keep things simpler. Perhaps I should include the curves and discuss them at greater length. They will be typical, unfortunately. Are you recommending that I do so? And what word would you prefer I use, since you don't like 'facts'? Would "worst case approximation/simplification" work for you? \$\endgroup\$ Apr 7 at 22:32
  • \$\begingroup\$ Well, like I said, they are not far off. For the about 5mA required, the output voltage is 2.5V with 2.7V supply, so calculated output impedance is about 40 ohms. \$\endgroup\$
    – Justme
    Apr 7 at 22:37
  • \$\begingroup\$ @Justme I made an adjustment in my terminology. Hope it satisfies. \$\endgroup\$ Apr 7 at 22:39
  • \$\begingroup\$ @Justme I really love the fact that Microchip adds all of the characterizing charts they do. I really hate using charts where the whole section starts with: "The following charts show typical behavior." You can't depend upon those. Or should not, anyway. \$\endgroup\$ Apr 7 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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