Dimming Algorithms

JCB

Member
These questions are with respect to dimming 120v AC LED String lights. I am curious if most AC controllers are using a timer interrupt and at what rate they are running assuming 256 dimming levels. I think the half wave is ~8333 microseconds, so I have been playing around with values like ~32 to 29 microseconds but wondering if I need to incorporate a faster rate and a dimming curve lookup table to translate back to 255? Also curious if turning on at the zero cross and turning off during the wave yields better results than turning off at the zero cross and turning on during the wave?
 
Keep in mind that if you sync with the zero cross the lights actually should turn off at the zero cross. So, and if I remember correctly, this is how the renard works, you can count down and from the zero cross then turn the light on for the remainder that you want. Then the light will turn of at the next zero cross and you go again.
I think also, for lower amperage parts the pin is left in the on state until the next zero cross. This is done to ensure that the output stays lit until the zero cross even if there is not enough amps to hold the triac on.

If you look at the renard code, (don't be afraid of the assembly language, its not that bad), Phil did a really nice job in leaving comments on how it all works and I also believe he has his calculated timings in there also.
 
The basic operation is to calculate how long from zero cross to delay turning on the TRIAC. The original renard chopped the half wave into 255 slices. I modified that into 100 slices and calculated the energy at each slice. Then balanced the slice width so that each slice represented the same amount energy. Slices at higher voltages are narrower than slices at lower voltages. This gave a far smoother dimming transition for incans. Then 255 slices seems to work better for LEDs.
 
That depends on the nature of the zero-cross signal. In the Renard controllers it's the output of an H11AA1 opto-coupler, and is a pulse that is somewhat under 1mS centered around each of the two zero-crossings for each AC cycle. The pulse width depends on the value of the resistor(s) in series with it's input diodes. After the end of the pulse there is likely a period of time when the AC line voltage is too low to allow the triacs to be reliably triggered (perhaps resulting in flickering), so there is a dead-time at the beginning of the cycle before the triac could be triggered for a full-brightness output. Likewise there is a period nearing the end of the cycle when the line-voltage is too low for reliable triggering, so the output to the triac for the lowest brightness should occur some time before the end of the AC half-cycle.

The alternative type of zero-cross that might be present in some other controllers is generated by a comparator, which results in a 60 hz (or 50 hz) square wave to the micro-controller. The program logic needs to take this difference into account.
 
One of the arduino based controllers had 192? dimming levels. If I remember right, there just wasn't enough time to do 256. I didn't dig into the code; I assume some kind of lookup or algorithm to take the values and convert. I would bet for the most part, the dimming was pretty much indistinguishable. When I looked a bit ago, unless you want to run an "old" mcu, any newer mcu could run circles around the 256 time slice and output a decent number of channels.

I think people have been hinting at the fact that most triacs will turn off automatically at zero. If you use a mosfet for control, you can turn on and off at your leisure but the circuit is more complex than using a triac when you are talking about AC. This GreatScott video was enlightening about leading vs trailing edge dimming.
 
Sort of a continuation of another thread I have built a controller MacGyver style with hockey puck SSRs, level shifters, (dirknerkle donated zero cross board) and an Arduino Due. I am now playing with the sketch to try to get good dimming. I have no EE training purely a software guy. Leaning on you guys to make sure I have a partial understanding of the theory / algorithm and I don't go down rabbit holes. I can take a picture of the contoller if you want to see it. This is the fifth controller like this that I have made. I think two of them dim reasonably well. Two of them have problems. From the hobby SSR boards, level shifters, zero cross detector I have not been able to build the same controller each time as the sub-components would no longer be available for sale.
 
I think controller #5 maybe chalked up as a failure. I did not scrutinize the startup time of the SSR. The spec sheet on my relays indicates a turn-on time of 1ms. I get some dimming but not what I would call good performance. I asked the company that sold me the initial batch of relays and they said they would support dimming. I guess I am a little bit more informed now. :)
 
These are the other threads:

Perf Boards & 74AHCT125

Phidget SSR


If someone confirms that 1ms startup time is too slow I am planning to respond to the Phidget SSR thread to prevent someone from going down the same rabbit hole. I noticed while researching my issues that an AI started using that 'Phidget SSR' thread as a source.
 
The turn off time is also 1ms so maybe you can get a "full cycle" out of it? I wonder what happens when you trigger it during that 1ms turn off time? It would take a small amount of calculation to figure out how to compensate but as you know a 1ms is around 12.5% of the half cycle so a little problem getting a 100% value. But if 90% is okay??

Seems slow for SSR but those are pretty heavy duty 20A relays. For comparison, a BTA16-600BRG turns on in 100ns add some micro seconds for an optocoupler and you are still way ahead of that relay.
 
FYI: The solution to turning on a device before there is enough current flow to latch the device is to NOT pulse the device. Just turn on the trigger and leave it on until just before the zero cross point.
 
I don't seem to have any issue getting full intensity but I have not been able to get really dim values. Does anyone know the turn on time requirements for a solid state relay to support 256 dim values similar to Renard style SSRs. I am wonder if any hockey puck style relays exist that would suffice. The Crydom D1210-10 has a turn on time of 0.02 msec. This relay is not really practical as it smurfin expensive.
 
I'm not so sure that 'turn-on time' limitations are the cause of not obtaining 'really dim values', whatever that is. There is a lower limit to dim a light can reliably get when it's driven by a triac-based SSR (which I suspect is the case here). This is determined by the instantaneous AC voltage at the time of the latest on-pulse in the AC half-wave cycle, and by the minimum reliable turn-on AC-voltage across the triac terminals.

The above also depends on the type of strings that are being used (LED vs incandescent). The minimum turn-on voltage of an LED string is much higher for an incandescent string. The minimum turn-on voltage for an incandescent string is the turn-on voltage of the opto-isolator+triac combo (maybe 4 or 5V), for an LED string it's sum of the forward voltage drop of all of the LEDs, which might be an order of magnitude higher for a 35-bulb string.

Bottom line, what you see might be the best that you can get with a triac-based SSR, and I'm not sure if the DIY SSR that Martin is suggesting would give any better results.

It's likely to be a different story with SSRs based on pulsing IGBT/MOSFET devices at much higher frequency than AC line frequency. That's a whole other can of worms that nobody (AFAIK) on this site other than angus40 and myself have played with, and I'm not going to suggest that as an option.
 
Just tossing 2 bits in for what its worth .
igbt's I found were premium for controlling ac lights being incans or led strings .
Full range of dimming and no special coding required .
Ground fault protection is a must though , as with all AC .
 
Back
Top