Hi all,
Some weeks ago I released my first version of my universal LED cube library, topic HERE. Currently I added a software brightness control. However I'm experiencing some problems with smooth fading.
The technique I'm using is called Bit Angle Modulation (at least that's how I found it). It's quite simple, you run a timer on a fixed frequency. Within this timer you will keep track of a counter which is increased with 1 every interrupt until equals a specified bit value and then is reset to 0. This end value will double every time the counter hits the current value(1...2...4...8...repeat) it will evaluate different ON or OFF states each interrupt according to the specified brightness. So lets say we have brightness 10, that means that bit 1 and bit 3 should be on (2 + 8 = 10) and bit 0 and bit 2 to be off. So there will be 15 interrupts in total to have evaluated bit 0, bit 1, bit 2 and bit 3. You will get a signal that looks exactly like the image below.
More info about BAM can be found HERE.
As you can see this will ensure that the LED will be dimmed, and indeed it does dim very well.
But here comes the problem... Whenever I try to fade (so cycle through brightness 1 to 15 and back again) the LEDs I will get a funky blink effect. So last week I hooked up my oscilloscope and found out an interesting issue with Bit Angle Modulation.
Lets say we are changing the brightness from 8/15 to 7/15. For brightness 8 bit 0, bit 1 and bit 2 will be off and bit 3 will be on. For brightness 7 bit 0, bit 1 and bit 2 will be on and bit 3 will be off. When we combine those two cycles we will get a signal shown in the image below (upper part). As you can see the ON period will be 15/15 for a very tiny moment, the next cycle will of course be normal again. Now when we change the brightness from 7/15 to 8/15, exactly the same will happen however the signal will be mirrored (lower part of the image below), what results in a ON period of 0/15 for a very tiny moment. I thought that this was causing the funky flicker I was seeing.
With this in mind I googled and found out someone that had exactly the same problem and had the same conclusion as I have (CLICK for topic). In that topic they seemed to found out a solution called Mirror Image Bit Angle Modulation. Simply said, this technique is doing exactly the same as the normal BAM however it is reversing the bit order every duty cycle. For more information how that works see that topic.
So with that in mind I did implemented a mirrored bit angle modulation for a single LED to test out if it removes the flicker. And in my case it didn't remove the flicker completely, however the people from the MIBAM topic seemed to fix the flicker with MIBAM. So I started drawing the expected signal in my notebook and verified it with my oscilloscope. And indeed I think MIBAM won't fix the flicker. Consider the image below. As you can see when we change the brightness from 8 to 7 (or vice versa), you will get a significant lower OFF time then a 'normal' cycle will have. I did put a red circle around the faulty OFF time and a green circle around the correct OFF time. As you can see when changing brightness you will come short exactly half the required OFF time to prevent the funky blinking.
I think MIBAM isn't that great at all, of course it will eliminate some of the funky blinking, however it also needs twice the required refresh frequency than the normal BAM.
I know only of one solution that will definitely work, that is cranking up the refresh frequency. When this is very high you won't notice that one 'faulty' cycle at all. While this will work for a small amount of LEDs, I think I can't get it to work at a higher amount of LEDs, for instance a 8x8x8 LED cube. Does anyone have any suggestions on the BAM technique, or maybe something that I'm missing with the MIBAM technique (as it seems to work for other people...). Thanks for your time!
EDIT:
Images are quite small, it's best to open them in a separate tab page.