TM16xx icon indicating copy to clipboard operation
TM16xx copied to clipboard

Per Digit LED Brightness

Open ShahzadaG opened this issue 6 months ago • 1 comments

Hey. Thanks for making this incredible library, it has been super helpful in my project. I appreciate all the work you have done!

I know that brightness for these displays is set on a global level, and there is no per digit brightness setting. But this is something I require for my project and I'm curious to see if anyone has tried it.

I think there are two possible ways of achieving this. The first is to skip frames for the digit you want to dim, for example, setting the digit to be clear one cycle, and on the next cycle. However, this isn't something I have tried and not sure what the result would look like.

Another approach, which I have tried is using PWM on my ESP32. This requires transistors to be able to PWM the display cycle of the TM1640. And this has actually worked quite well for me, although there is a slight flickering of the LED.

Curious to hear what people think, and if this is something that has been tried before.

Image

ShahzadaG avatar May 24 '25 16:05 ShahzadaG

Hello @ShahzadaG , interesting task you've set yourself. There have been times that I've been pondering at this too, but I've not experimented with any such thing yet.

Your first approach is one that I've seen being used in some other LED projects. The main limitation I think would be the speed at which you can update the displays and the frequency of persistence of vision to achieve. For the least bright digit you'd probably still want 20-30 frames per second; ie. a 50ms interval or less. Somewhere in a TM1640 datasheet I read about a maximum clock-speed of 1MHz for data and a typical oscillation frequency of 450kHz. I'll leave it up to you (or another reader) to calculate how many brightness levels could be implemented in software without flickering using this approach. Unfortunately my library is definitely not optimized for speed and uses delays to bit-bang slow digitalWrite() calls. To get a first impression one could do a simple loop that prints a text string with spaces for dimmed digits. I think the result would be disappointing and blocking the entire processor.

Your second approach seems more manageable and is somewhat comparable to something I've seen before. In the TM1680 datasheet you can find three different circuits to control power to the LEDs. The low power mode directly connects the LEDs to the SEG/GRD lines. (This is how I use all my TM16xx chips to drive LED displays). It also shows a medium and high current circuits, in which the medium current circuit has transistors/mosfets on the GRD lines and the high current circuit also has them on the SEG lines.

One question: how do you generate the PWM signals? To limit use of GPIO lines and perhaps reduce flickering, you could try a separate PWM chip, such as the PCA9685 12 Bit PWM driver. You can find this chip on some popular servo driver modules, but the datasheet presents it as a 16 channel PWM driver for LEDs.

To further investigate the flickering you probably need to hookup a scope. Perhaps the voltage is too low at specific times. in this reply you can see a short video of a TM1640 that flickered in a quite ugly way. Eventually one of the factors seemed related to the very specific TM1640 chip used being more sensitive to power issues than other TM1640 chips in my collection.

Edit: thinking a bit more of possible causes of flickering: the TM1640 also uses some sort of PWM/multiplexing to drive the SEG/GRD lines at the desired brightness. Since it can't drive all lines at the same time it pulses them one after another. Perhaps the uses frequency is interfering a bit with your PWM frequency, causing something like the banding you can see when filming a monitor. Perhaps changing the PWM frequency can improve the flickering you perceive...

maxint-rd avatar May 24 '25 18:05 maxint-rd

Assuming there no further questions I'll close this issue now. Feel free to reopen or post a new...

maxint-rd avatar Nov 22 '25 19:11 maxint-rd