I am designing a binary coded watch with an attiny1616 MCU and an LED watchface. The matrix I designed is displayed below along with the rest of the schematic. The LEDs is 2.1V 30mA and I plan to drive the anode with PWM. The supply voltage is 3V from a CR2032 coin cell. What resistor values do the LEDs need, and will resistors degrade PWM performance? Do I need resistors at all?
-
1\$\begingroup\$ What is the actual current you expect to drive through the LEDs? You don't expect to sink 120mA with a GPIO pin, do you? Or to source 120mA from your coin cell? \$\endgroup\$– Elliot AldersonCommented Jul 24, 2022 at 15:00
-
\$\begingroup\$ It’s impossible to supply each LED with 30mA average from a CR2032, that would be 600mA, maybe 200x what is available. Even if only one LED is ever intended to appear on at a time, it’s still 5-10x too much. \$\endgroup\$– Spehro 'speff' PefhanyCommented Jul 24, 2022 at 15:02
-
\$\begingroup\$ Those are the specifications of the LED, the actual current per LED will be much closer to 10mA, would it be better to do this with PWM or with a resistor? The maximum number of LEDs on at once is 14 due to the time encoding. For power savings the watch face will not be on at all times. \$\endgroup\$– AWESDUDE COOLCommented Jul 24, 2022 at 15:07
-
\$\begingroup\$ Would it be better to use a li-ion cell for this? \$\endgroup\$– AWESDUDE COOLCommented Jul 24, 2022 at 15:09
4 Answers
According to the attiny1616 datasheet the absolute max source/sink current of any IO pin is +/-40mA and the total source or the total sink of all IO pins is limited to 100mA.
I am assuming you shall be driving R1 to R4 high, one at a time. With your advertised resistor placement, the brightness of a particular LED on a given channel (eg. on R1) will depend on how many other LEDs are also illuminated on that same channel. This is because they all share the same current limiting resistor. To avoid this problem, you should put the current limiting resistors on the C1-C6 lines instead.
If you do this then you must choose a resistance so that even when all LEDs are on, you don't exceed the maximum source current (40mA) on the R1-R4 pins. Dividing 40mA/6channels = ~6mA allocation to each C1-C6. Looking at the LED datasheet the forward voltage drop at 6mA is about 1.9V. So 180ohm resistors would work well.
Assuming each of the R1-R4 channels are on for 25% of the time. The average LED current would be 6mA x 25% = 1.5mA. That's still enough current to have a bright enough LED for you purposes.
Ensure you run at a high enough frequency to have no flicker (>90 Hz). Perhaps add a 100uF decoupling capacitor to smoothen and reduce the peak currents on you small coin cell battery.
-
\$\begingroup\$ Yes, modern LEDs are very bright at low currents. \$\endgroup\$ Commented Jul 24, 2022 at 15:41
-
\$\begingroup\$ Thank you for the help, I had a 100uF capacitor that was just a typo, good catch \$\endgroup\$ Commented Jul 25, 2022 at 16:16
This is not something you can calculate because it depends on how bright the LEDs look to you and what is acceptable. You can't get anywhere near the rated current.
I suggest you try playing around with a breadboard with a few K and see if that's usable. If you don't have a breadboard to test, multiply the resistor value by 4 (your matrix when properly driven will have a 1:4 duty cycle) and test that brightness. For example, if a 5K resistor was to be deemed suitable for the final unit try a 20K resistor with a CR2032 + LED and see how it looks to you. The time to do this is before you finalize circuit boards and send them off for fabrication and PCBA.
If that's too dim you may have to look at some other power source such as a Li-ion battery, but of course that raises a whole bunch of other considerations (charging and whether you have enough energy for the device to be useable for long enough). Smart watches are pretty clever with how they switch their LEDs (backlight or OLED) to maximize time between charges.
$$ R = \frac{V-V_{f}}{I_{f}} = \frac{3-2.1}{0.03} = 30 \Omega $$=
-
3\$\begingroup\$ This can't be a correct answer. While calculation is correct in theory, the battery can't provide 30mA per LED and the MCU absoute maximum ratings would be exceeded if more than one LED is turned on at a time. \$\endgroup\$– JustmeCommented Jul 24, 2022 at 15:28
-
\$\begingroup\$ This could work if the firmware ensures that only a single LED is enabled at any given time. \$\endgroup\$– VelvetCommented Jul 24, 2022 at 17:25
You do not need any resistors, the internal resistance of the battery will be the limiting factor on how much current gets to the LEDs. You can then PWM to control the brightness of the LEDs.
In my experience it is also usually easier to scan the LEDs individually rather than by full row or column. If you try to light more than one LED at once then you will have to compensate for the decreased brightness becuase both LEDs are drawing current at the same time. That chip should be more than fast enough to do this without visual flashing.
Finally, if you do not want to display to get dimmer as the battery voltage drops, you can compensate by measuring the battery voltage and then increasing the LED duty cycle as it goes down.
-
1\$\begingroup\$ This can't be a correct answer. Without a resistor the current can easily exceed the absolute maximum ratings, both for the IO pin and the LED. The battery output voltage would also get clamped to the LED forward voltage and if your MCU needs more than 2.1V to run at the speed you want it will not run. A CR2032 battery can't output the current needed for multiple LEDs at the same time. \$\endgroup\$– JustmeCommented Jul 24, 2022 at 15:31
-
\$\begingroup\$ @Justme It definitely works, I've done it on dozens of products that have shipped 10's of thousands of units and never had a problem - try it and see! It not only works - it is better since it gives you a wider dynamic range of possible LED brightnesses and driving an LED at higher current but lower duty cycle is more power efficient. The ATTINY can run down to 1.8V. \$\endgroup\$– bigjoshCommented Jul 25, 2022 at 3:43
-
\$\begingroup\$ It depends what products those are. For toys it does not matter. For any real product, where reliability matters, you would not leave out the resistors, as you are stressing the components. So even if you have never had an issue in your scenario, please don't suggest other people to use bad practices, as it may not work in their scenario. \$\endgroup\$– JustmeCommented Jul 25, 2022 at 8:30
-
\$\begingroup\$ @Justme Can you refer to any literature or empirical data showing that this "stresses" the components or effects reliability? Which components do you think are being stressed and how? What failure modes do you predict? \$\endgroup\$– bigjoshCommented Jul 26, 2022 at 13:37
-
\$\begingroup\$ A CR2032 battery has about 10-20 ohms internal resistance, and MCU IO driver also might have some 20-30 ohms of driver impedance. It is likely that safe operating area and absolute maximum ratings are exceeded and localized heating might be too much for the IO driver and the LED. Sure, some LEDs are rated for nominal current and allow higher pulsed current given the PWM duty, period and current are within specs. But if the LED is not rated for it, you are overheating it too. So the LED or IO pin can degrade. If the LED Vf is lower than what MCU needs to operate it may reset/hang. \$\endgroup\$– JustmeCommented Jul 26, 2022 at 14:00