2. Dimming LEDs
The ability to dim LEDs is an important feature for many LED drivers. It is especially critical when color mixing is required. The two commonly used dimming methods are analog dimming and PWM dimming. Advantages and disadvantages of each were described before as well. http://neuroelec.com/2011/02/led-dimming-methods/
In here, let me tell you how I implement two dimming methods in the shield.
PWM dimming is achieved by fast turn on and off. Depending on how long you turn on, brightness of LED is determined. Since the pulse of PWM signal is short, human normally don’t notice the turn on and off at higher than 100Hz. Dimming ratio is determined by turn on and off speed of LED driver. If LED driver can turn on and off LEDs within 1us, 1:3000 dimming ratio can be achieved at 100-150Hz PWM signal as long as PWM signal has a such precision.
Implementation of PWM can be simple, since Arduino can generate PWM. All I need to do is connect PWM output pins from Arduino to LT3496 PWM input pins. There is two problems with that. First one is Arduino PWM has two different frequency depending on pins(500Hz and 1KHz). Default frequency is a bit high and PWM signal is 8 bit resolution. So, dimming ratio you can get is 1:256. Second, more important one is there are only 6 hardware PWM pins in an Arduino which limit the number of shield can be stacked.
I really want to have shields to be stacked more than two. So I decide to put serial controlled PWM signal generator, ATTINY85, small and cheap AVR microcontroller. Attiny is is quite popular for this kind of things. As you may know there is a quite popular product, BlinkM is based on Atttiny. The idea is generating PWM signal from Attiny which communicate with Arduino by I2C protocol. The beauty of I2C is many devices can be controlled in a single bus which use 2 pins (A4, A5) in Arduino. So It does not matter how many shields are stacked, with just two pins we can control as many shield we want. I2C bus use 7 bit address so theoretically 128 shield can be stacked. In practice, maybe 20 stacked shields are maximum due to the rated current of stackable pins. If you independently power the shields, 100 may be OK.
Analog dimming is not a popular method for dimming LED. Because of disadvantages that I describe before as well as requirement of adjustable voltage input. Many LED driver offer pins that limit the current flow to LED. Maximum current is set by current sense resistor, and driver can lower the limit by current adjust pin which normally take certain voltage. In LT3496, There are CTRL pins to limit the current. If the voltage to the pin is > 1V, the driver output maximum current set by current sense resistor. If voltage to the pin is < 1, the driver linearly decrease the output current. For fixed current limit, it is normally just tied to the internal voltage reference pin. Some led driver board left a spot for additional current sense resistor to lower the current limit or simple jumpers. More flexible driver boards have a trimmer or potentiometer to adjust current limit.
Ultimate flexibility on current limit can be achieved by either digital potentiometer or DAC. By using one of those not only you have freedom on current limit adjustment but also you have possibility of analog dimming. Since DigitalPot and DAC adjust output fast, it can be used for dynamic current adjustment.
As you see in my first post, I initially use digital potentiometer, AD5254 along with a resistor. It is basically variable voltage dividers. AD5254 is four channel pot and has eeprom to save the settings. Main problems of this approach are output voltage is vulnerable to input voltage change and accuracy of the resistors. Input voltage can varies in some extent. Also total resistance of the potentiometer is not accurate and different on each channels. To correct this problem, I need to put more components and make the circuit complicated. So I dropped the digital potentiometer. Instead looking into a DAC. There were three reasons why I chose AD5254. It is 8 bit potentiometer which is quite high resolution for potentiometer. It use I2C protocol, so I don’t need to waste any more Arduino pins. People who don’t need analog dimming, they can set current value into EEPROM, and forget about it. AD5254 read the values from EEPROM when powering up. Finding a DAC that has all those good things was not easy. Particularly DAC with the EEPROM is rare. Luckily, I found a perfect DAC for this. Microchip MCP4728 is I2C quad 12 bit DAC with EERPOM. Everything that I have in AD5254 with higher resolution and faster output. Even Availability and price was better. What can I ask more?
Three out of four pins are connected to CTRL pins of LT3496, one is connected to frequency adjustment pin. Now, Arduino control current limit of three channel independently and operating frequency. EEPROM of MCP4728 can store settings. Also, MCP4728 adjust current output within 1ms which is more than enough for analog dimming. Since 1ms adjustment time result in 1000Hz, you can even make analog dimming to pseudo-PWM.
MCP4728 has a programmable address feature. Users can set I2C slave address into EEPROM without physical jumper changes. Detailed explanation was posted before: http://neuroelec.com/2011/02/soft-i2c-and-programmable-i2c-address/
If you use analog dimming, maximum stackable shields are 8, since MCP4728 allow 8 programmable addresses.