Shop OBEX P1 Docs P2 Docs Learn Events
Modified PWM for Triac Gating ? — Parallax Forums

Modified PWM for Triac Gating ?

Hi All,

Application: AC lamp dimmer.
Circuit: old-school wave chopping via triac.

Please before you say this won't work, hear me out ... :)

I'm familiar with many of the quirks of triacs used in dimmers, i.e. they need zero-crossing detection, they lock on, etc.

Because most MC libs do PWM out of the box, and triac gating is basically an on/off deal, I've been wondering if modifying the PWM code might work to drive the gate, switching the device on and off at the appropriate point in the half cycles.

Modified here means Pulse on = Gate on, Pulse off = Gate off. (Or is that a dumb idea?)

I'm trying to step back, and need more eyes, to make sure I'm not making this more complicated than it needs to be.

I'd use this simple circuit: a zero crossing detector, opto-isolated, fed in into the MC. The code, in turn, triggers the modified PWM output, via another opti-iso into a level setter to get the right gating current.

Maybe there is an easier way, using the same circuit but different code? For instance, have just a simple timer, triggered by the zero crossing. Timer on/off length = Gate on/off time. (Notice how similar that is to PWM ? ) In this approach, there'd need to be a lookup table --- something like Percentage of desired Brightness -> Timer Length. Off the cuff, it seems like moding the PWM or coding a lookup is about the same amount of effort. (?)

I'm thinking of using the the BTA41-600BRG triac (BTA41-600BRG). It has enough headroom to handle my need of a constant max 10amps at 120VAC.

thoughts, comments, ideas most welcome.
Thanks!
«1

Comments

  • kwinnkwinn Posts: 8,697
    IMO it would be simpler to use a table lookup containing the delay time for the desired brightness level rather than trying to modify the PWM code. The light output is not linear relative to on time, so getting smooth intensity increase/decrease is difficult. A small table (16 or 32 entries) that holds the delays from the zero crossing will provide a smooth transition over the full range.
  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2017-04-22 20:27
    thanks, kwinn - just the kind of feedback needed. A table would be easy to tweak empirically, starting with a reasonable guess that the light output is directly proportional to the area under the sine curve from on point to cut off. [My calculus is rusty, but I think that's the integral under the curve? @PhiPi ]

    Even for a small device, 32 table entries is a small memory footprint. Do you think 64 transitions would be too fine grained?
  • jmgjmg Posts: 15,173
    Application: AC lamp dimmer....a constant max 10amps at 120VAC.
    In this approach, there'd need to be a lookup table --- something like Percentage of desired Brightness -> Timer Length.
    ... coding a lookup is about the same amount of effort. (?)
    It's been a while, but we did theatre dimmer controls and IIRC there was a standard profile curve, for incandescent lighting, that also takes into account the PTC nature of the filament. Google can probably find such a table.
    Not sure about newer LED dimming curves, so this may need to be switchable.

    Even for a small device, 32 table entries is a small memory footprint. Do you think 64 transitions would be too fine grained?

    I would fit even more, as the eye is very sensitive to flicker, and a control on any boundary will be prone to flickering between two values.

    I'd use this simple circuit: a zero crossing detector, opto-isolated, fed in into the MC. The code, in turn, triggers the modified PWM output, via another opti-iso into a level setter to get the right gating current.
    It's not really quite PWM you want, as you do not want a repeating signal.
    You need a variable delay from ZCD to Gate leading edge, and then need care to terminate that gate pulse comfortably before the next ZCD.
    Some designs burst fire the gates to save a little energy.
    You also need to watch for phase variances in inductive loads (halogen ballasts etc), and better designs check for Triac-off with a ZCD across the Triac, (effectively current zero cross) and you need to control pairs of half cycles identically, to avoid unbalanced loads.

  • The Prop chip has a ZCD and phase control gating built-in, it's called a COG. I'm not being funny, I'm switching banks of 1,000A inverse parallel SCRs (back-to-back SCRs that work better than a TRIAC) and everything you need is right there, just write a little bit of code and set a COG on the task. PWM is of absolutely no help at all for phase control and especially when you have a "dedicated peripheral" to do the job so much better. Just WAITPxx for the ZCD, turn on the trigger, WAITCNT, turn off the trigger. How hard can it be?
  • jmgjmg Posts: 15,173
    I'm not being funny, I'm switching banks of 1,000A inverse parallel SCRs (back-to-back SCRs that work better than a TRIAC) and everything you need is right there, just write a little bit of code and set a COG on the task.

    Impressive. What do those monsters cost ?
    Do you manage as one-pair per COG, or more ?

  • Just WAITPxx for the ZCD, turn on the trigger, WAITCNT, turn off the trigger. How hard can it be?
    Actually, it's "WAITPxx for the ZCD, WAITCNT, then turn on the trigger, turn off the trigger."

    But, still, pretty easy! :)

    -Phil
  • kwinnkwinn Posts: 8,697
    thanks, kwinn - just the kind of feedback needed. A table would be easy to tweak empirically, starting with a reasonable guess that the light output is directly proportional to the area under the sine curve from on point to cut off. [My calculus is rusty, but I think that's the integral under the curve? @PhiPi ]

    Even for a small device, 32 table entries is a small memory footprint. Do you think 64 transitions would be too fine grained?

    Unfortunately the light output is not directly proportional to the the area under the sine curve. Both intensity and color spectrum are non linear. Best to see if you can find a table on the internet if you can.

    I do not think a 64 entry table is too fine grained, but even a 32 entry table is adequate and you can always extrapolate between two entries.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2017-04-23 04:51
    Just WAITPxx for the ZCD, turn on the trigger, WAITCNT, turn off the trigger. How hard can it be?
    Actually, it's "WAITPxx for the ZCD, WAITCNT, then turn on the trigger, turn off the trigger."

    But, still, pretty easy! :)

    -Phil

    Yes - that's what we normally do for phase control but I must have been thinking about what I do with the SCRs as I don't need nor desire phase control in this application. In fact I prearm the opposing SCR of the pair so that the very moment the voltage and current are right it will conduct. This avoids needing an accurate ZCD too.

    btw, this current is only being used as an injection current, so the actual load current is very high. In fact I had a faulty half of an SCR brick in the chain that failed and shorted out the supply line momentarily. The end result was a very big mess, lots of black smoke from the insulation off several of the 1" diameter copper cables that completely melted away, and to figure out why the breaker for this "control" current didn't trip although the big fuses in the distribution panel ended up blowing.

    Each brick is big enough to host its own little Prop module over my ping-pong RS485 network using a 10-way IDC cable but even still there are a couple of tiny PIC chips that the Prop communicates with over a couple of solid-state isolation barriers for the SCR pair. I did post a video showing how I could broadcast to all these Props or chat with them individually as if I had a direct connection, which means I can do this over Telnet from far away too if need be.

  • kwinnkwinn Posts: 8,697
    jmg wrote: »
    Application: AC lamp dimmer....a constant max 10amps at 120VAC.
    In this approach, there'd need to be a lookup table --- something like Percentage of desired Brightness -> Timer Length.
    ... coding a lookup is about the same amount of effort. (?)
    It's been a while, but we did theatre dimmer controls and IIRC there was a standard profile curve, for incandescent lighting, that also takes into account the PTC nature of the filament. Google can probably find such a table.
    Not sure about newer LED dimming curves, so this may need to be switchable.

    Even for a small device, 32 table entries is a small memory footprint. Do you think 64 transitions would be too fine grained?

    I would fit even more, as the eye is very sensitive to flicker, and a control on any boundary will be prone to flickering between two values.
    With this being a digital control system I don't see that flickering between two values would be a problem unless an analog input signal was used to control the brightness. Even if that was the case the software could avoid the problem.
    I'd use this simple circuit: a zero crossing detector, opto-isolated, fed in into the MC. The code, in turn, triggers the modified PWM output, via another opti-iso into a level setter to get the right gating current.
    It's not really quite PWM you want, as you do not want a repeating signal.
    You need a variable delay from ZCD to Gate leading edge, and then need care to terminate that gate pulse comfortably before the next ZCD.
    Some designs burst fire the gates to save a little energy.
    You also need to watch for phase variances in inductive loads (halogen ballasts etc), and better designs check for Triac-off with a ZCD across the Triac, (effectively current zero cross) and you need to control pairs of half cycles identically, to avoid unbalanced loads.

    Exactly. The cog waits for a zero crossing which then triggers another wait for the time specified in the table, at which time a trigger pulse is sent to the Triac.
  • I've attached a simple object that will do AC dimming on up to four channels. It's very simple, and seems to work the way I want it to work.
  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2017-04-25 18:28
    thanks everyone. A tad rusty here, it's been 40 years since I've done anything serious with dimmers. I knew I could count on you for very helpful replies.

    While I was writing this, Jon posted a spin obj - great, thanks - I will review it asap and it may well answer several questions I was going to ask.
    1,000A SCRs (back-to-back)
    Both Cool and Yikes! Although that's 100 times what I'd need, would an inverse parallel SCR set provide any benefit at lower switching power over a Triac config? (Load will be incandescent, then down the road LED <- @jmg, yes I do need to research it more.)
    I prearm the opposing SCR of the pair [...]
    Peter, you lost me there. I thought SCRs (and Triacs, etc) were either gated on or off. How do you "prearm" one?

  • jmgjmg Posts: 15,173
    Although that's 100 times what I'd need, would an inverse parallel SCR set provide any benefit at lower switching power over a Triac config?
    Triacs are simpler, but from memory, SCRs have better dV/dT and i2t fusing specs (ie are more rugged)
    Bulbs blowing, ideally should not kill the dimmer... :)
    As powers push up, SCRs can also spread the hot-spot more, by using two packages.

    I prearm the opposing SCR of the pair [...]
    Peter, you lost me there. I thought SCRs (and Triacs, etc) were either gated on or off. How do you "prearm" one?
    I think here, Peter means with a SCR you can apply the gate pulse early, and it will then naturally turn on as soon as the voltage reverses.
    That assumes you want 100% conduction times, but also want to save gate power.

  • I prearm the opposing SCR of the pair [...]
    Peter, you lost me ... How do you "prearm" one?
    I think here, Peter means with a SCR you can apply the gate pulse early, and it will then naturally turn on as soon as the voltage reverses.
    That assumes you want 100% conduction times, but also want to save gate power.
    Oh OK, got it - I think :)
    This avoids needing an accurate ZCD too.
    That would be sweet - in that config, for a ZCD, could I get away with using something a rudimentary as the approriate series resistor and cap on each leg feeding the inverse-parallel LEDS of an opto-iso like an H11AA1 https://fairchildsemi.com/datasheets/H1/H11AA1M.pdf ?
  • jmgjmg Posts: 15,173
    edited 2017-04-25 23:03
    This avoids needing an accurate ZCD too.
    That would be sweet - in that config, for a ZCD, could I get away with using something a rudimentary as the approriate series resistor and cap on each leg feeding the inverse-parallel LEDS of an opto-iso like an H11AA1 https://fairchildsemi.com/datasheets/H1/H11AA1M.pdf ?
    If you want phase control dimming, you cannot use Peter's approach, (except if you wanted 100% ON, lowest RFI, as a special case)
    For Phase dimming, you turn off on voltage reversal, and delay the eventual turn-on from there.

    Rather than a H11AA1, it is probably simpler to drive a >> 10A Triac, using a Non-ZeroCross Triac Trigger opto, like MOC3052S (1kV/µs), or more $, but better specs, FOD4218S (10kV/µs, < 1.3mA trig)

    FOD4218S shows Triac and SCR use circuits.

    https://www.fairchildsemi.com/products/optoelectronics/triac-driver-optocouplers/random-phase-triac-driver/
  • Hey, thanks, jmg - that's spot on. Cool, "random-phase" is a new term to me - and explains why I wasn't turning up devices that should obviously exist: all in one package, targeted at MCU's. The specific device references are appreciated; now I know what to fish for.

    OK good too that you say Peter's approach wouldn't do phase control - I just assumed inverse-parallel SCRs could be set up to trigger that way.
    For Phase dimming, you turn off on voltage reversal, and delay the eventual turn-on from there.
    Best one-line description yet.
    Bulbs blowing, ideally should not kill the dimmer...
    Which explains why really cheap dimmers zonk out after one or two bulbs go. (Caveat Emptor :))
  • jmgjmg Posts: 15,173
    OK good too that you say Peter's approach wouldn't do phase control - I just assumed inverse-parallel SCRs could be set up to trigger that way.
    inverse-parallel SCRs can do phase control fine, see the circuits in the FOD4218S data.
    (I think that FOD4218S is actually built using 2xSCRs, which is how they get the high dV/dT, and also why the price bumps a little )
  • hmm now I am confused ... I thought Peter's circuit is a back-to-back pair of inverse parallel SCRs?
  • jmgjmg Posts: 15,173
    hmm now I am confused ... I thought Peter's circuit is a back-to-back pair of inverse parallel SCRs?
    well yes, but the pre-arm Peter mentioned, is the detail that is not phase-control compatible.
    The hardware of back-to-back pair of inverse parallel SCRs is capable of Phase control, and that is how soft start systems work. Brief phase control, then run at 100% ON.

  • ah, ok - and that helps clarify why the pre-arm is all or nothing.
  • jmgjmg Posts: 15,173
    edited 2017-04-26 00:35
    ah, ok - and that helps clarify why the pre-arm is all or nothing.

    I'll just add a clarify that if you go for the clean simplicity of Opto-Triac triggering, pre-arm has less meaning anyway, as the Opto-Triac is itself a triggered drive.
    There needs to be some small voltage build up, across Opto-Triac + surge-rated gate resistor + Main Triac/SCR gate, enough to get above the Main Triac/SCR trigger threshold.
    Monsters like the ones Peter drives, likely have their own local floating gate power supplies, avoiding that gate resistor - Anode path.
    Looks like 2V / 100mA is a common trigger for bigger SCRs, & < 5V Reverse.


  • Triac phase control circuits should be simple and those little triac optos make it very easy too but then again you can triacs with the optos built in too. Pre-arm is more to do with achieving a smooth changeover in banks of SCRs without cross-firing but you can't do the same thing with triacs nor would you want to.
  • jmgjmg Posts: 15,173
    Pre-arm is more to do with achieving a smooth changeover in banks of SCRs without cross-firing....
    Can you expand on this ?
    Does this mean you run multiple SCRs in some time-sequence manner, to spread the thermal load over many banks ?
    Sounds like even more of a monster..!
  • 12 SCRs per phase bank but some directional, some 1 of 4 gating. It is a monster, and dangerous.
  • That would be sweet - in that config, for a ZCD, could I get away with using something a rudimentary as the approriate series resistor and cap on each leg feeding the inverse-parallel LEDS of an opto-iso like an H11AA1 https://fairchildsemi.com/datasheets/H1/H11AA1M.pdf ?

    I use the H11AA1 in my dimmer circuit.

  • jmgjmg Posts: 15,173
    edited 2017-04-26 21:04
    That would be sweet - in that config, for a ZCD, could I get away with using something a rudimentary as the approriate series resistor and cap on each leg feeding the inverse-parallel LEDS of an opto-iso like an H11AA1
    I misread the question earlier.
    Series caps need care, as that shifts the 'zero' in the zero crossing, but you can fix that in a P1 with another shift, once you've decided the line frequency.
    Optos have poor gain tolerance, and drift, so you may want to add more smarts to centre timing between the two ZCD edges. (assumes matched diodes, and symmetric sine AC)
    This also allows lower currents into the opto, and tolerates CTR and drift.
    Lower current optos like SFH6286-4 also ease the design.
  • Here's a simple circuit that I posted back in 2012. It will provide transitions at the zero crossings (plus about 200 uSec) with no false edges at the transition points:

    attachment.php?attachmentid=95714&d=1348026516

    The output waveform is virtually symmetrical. On my bench, the duty cycle was 49.55%.

    -Phil
  • 12 SCRs per phase bank .. a monster, and dangerous.
    Somehow, I get the feeling that's not what's controlling your avatar's propeller beanie ;-P
    JonnyMac wrote: »
    I use the H11AA1 in my dimmer circuit.
    good, thanks, that confirms I'm on the right track here.
    a simple circuit ... I posted back in 2012. ... zero crossings

    appreciate that. ok, good too, I was mulling over using two optos in inverse parallel like that, instead of the AC input in the H11AA1.

    Aside from operating voltage, is there any specific (crucial) reason to select the H11D3 over others in the family, or similar ones from other vendors? It's (relatively) pricey.


  • jmgjmg Posts: 15,173
    edited 2017-04-30 04:25
    a simple circuit ... I posted back in 2012. ... zero crossings

    appreciate that. ok, good too, I was mulling over using two optos in inverse parallel like that, instead of the AC input in the H11AA1.

    Aside from operating voltage, is there any specific (crucial) reason to select the H11D3 over others in the family, or similar ones from other vendors? It's (relatively) pricey.
    Any opto would do, but some points to note
    * If you do not use the base, best to buy an opto with base not connected.
    * For Mains ZCD, series resistor power is significant, so lowest current spec'd optos are better; 10mA is ancient, good ones spec at 1mA
    * Channel matching will be better on AC input opto, as the TRX is common, just LEDs can vary.
    Possibly two optos in one package, might get closer to AC matching.
    * Phil's circuit has a nifty series connection of the optos.
    That gives a tri-state region, so has very low static current, and high sensitivity (pluses), but it only has one edge per crossing, so you lose the ability to interpolate the two edges for a near perfect zero point.

  • For Zero Crossing detection, some of the circuits I've seen used resistors direct into the microcontroller input (220K each, 1/2 watt). They work good in terms of saving some board space, but suffers from noise issues ( and safety, it's not isolated!! :o ). Some of the application notes I've seen used an optoisolator in between too. Which one is better? Both has disadvantages and advantages themselves, so the designer should decide.

    Ah, and chopping sine wave using the "leading edge" method creates a lot of noise. A small network of inductors and resistors can suppress the noise.

    Make sure the triacs are also isolated with drivers. I've seen the ones without isolations, but I do not recommend them due to the safety issues on it.



  • jmgjmg Posts: 15,173
    For Zero Crossing detection, some of the circuits I've seen used resistors direct into the microcontroller input (220K each, 1/2 watt). They work good in terms of saving some board space, but suffers from noise issues ( and safety, it's not isolated!! :o ).
    Yikes, that is a quite low value to non-isolate. Would trip many leakage breakers ?

    I have seen special resistors like the ex Philips VR68 series, used without isolation, they are rated to 10kV, and many-megs keeps the ground current to well below safe levels. 10M~33M or even their top end 68M could be considered with modern sub uA leakage MCU pins.


Sign In or Register to comment.