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

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

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.

  1. On last version of your shield, AtTiny is replaced with a PCA9685.
    Do you think that comme back to AtTiny could be a solution with the https://code.google.com/p/codalyze/wiki/CyzRgb frimware for example ?

  2. Finally do you have comparaison between these solutions :
    and why not the TLC59711 (for the 16bit)

    • No, I have no comparison. The PCA9685 simply eliminates having to have an ISP header on the board and also eliminates the headache of having to program each individual shield. In my projects I use a Teensy 3 board which hosts an ARM Cortex M4 core at 96MHz. Plenty of power to implement everything the CyzRgb firmware can do and then some.
      The TLC59711 is an interesting chip. However, reading through its spec sheet, similar to other chips it does use a two-wire interface but it does not use the standard I2C protocol. The chips on the current shield all use the “standard” I2C protocol at up to 1MHz.

      Only very few specialized applications would really benefit from a 16 dimming resolution. My own lighting systems use a lookup table with 256 12-bit CIE lab brightness corrected entries for a more visually linear fading experience. So I only have 256 = 8-bit steps. And with that I can smoothly fade between colors all day long. No 16 bit necessary!
      The library that goes with the shield has another function that uses 1024 12-bit and provides even smother fading for very slow fading at very low light levels. Actually that last sentence is the only application where 16-bit could be necessary. I already used the word “slow” in the sentence above. Fading speed is an essential ingredient in that formula that I have not seen mentioned in ant of the discussions for example on the Arduino Forum. I’ve experimented with this quite a bit and you’d have to dim very slowly to complete darkness to see steps with 12-bit. In 95% or more of day-to-day applications this makes NO difference. What does make a difference, however is practical experience rather than just thought experiments.

    • For a next shield (actually, I may decide not to design it in a shield format) for a more advanced project I am looking at a 4-Channel LED driver that can drive up to 1A constant current per channel or more. I’ve found the PowerPSoC from Cypress Semiconductors. This is a 4-Channel LED driver with an integrated micro-controller. This would not only allow I2C but also RS485/DMX512 directly to the driver. Yummy!
      Coincidentally this one also offers 16-bit dimming per channel and not just simple PWM dimming but also what Cyprss calls PRISM, a pseudo randomized PWM to reduce EMI.

  3. That Cypress SoC looks very cool! Did you give it a try? I’m quite interested in a 4-channel driver. I’m also looking at the MY9942 that has integrated DMX and gamma corrected PWM. http://www.my-semi.com.tw/content/products/product_mean.aspx?id=16

    • Hi Michael,

      No, I’ve not gotten around to it. However for prototyping (or more) I’ve found a 4channel board utilizing the Power PSoC – at least that’s what I think based on the layout compared with a pinout of the Power PSoC. It is not per se an Arduino shield but marginally larger. This is distributed in the USA by Saelig.com. At ~$74 its not exactly cheap but it offers a lot o flexibility.

      I’ve come across the MY9942 as well but it only powers up to 350mA LEDs which is too little for my projects. The Power PSoC can power up to 1A per channel with the internal MOS FETs and even more with external MOS FETs. Using the internal MOS FETs is a very nice way to keep the component count down. Not an unimportant topic if the boards are hand populated 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: