Page 1 of 1

Triac phase control for lamp dimmer

PostPosted: Tue Apr 10, 2007 12:46 am
by dsptony

I hope someone can help me. I would like to dim a tungsten light bulb. I have read the Salvo tutorials so far but am not sure how to approach this problem. I have a zero crossing input and depending on the controller setting then at a fixed time after receiving a zero cross signal I need to toggle a control signal on the triac that is acting like a switch for mains. This is happening every half cycle of mains, so a worst-case period of 8.3 ms at 60Hz. I was thinking of a resolution of 100 steps within that, 1% duty cycle steps. (let me know if I need to explain that more).

The problem is that there cannot be too much variation on the switching point or else the bulb appears to flicker to the human eye. I need to be able to have a reasonably precise, adjustable, delay that is started upon receiving a zero crossing event (using PIC so intended to use “interrupt on change” I/O feature). It doesn’t matter if the delay timer starts a little late or early, but it must be consistent over the cycles.

Thanks for considering this. I am working on the project right now so will give results here if I get any suggestions. In the mean time I had thought to try using the zero crossing event to start a precise timer (not my system timer which would run slower) to add the phase delay, which would then trigger an interrupt event to toggle the triac.


Re: Triac phase control for lamp dimmer

PostPosted: Tue Apr 10, 2007 7:26 am
by aek
Well, the deal here is your accuracy within an 8.3ms period, with 100 step accuracy (83us steps) and minimal jitter.

You don't mention your clock speed, but I'll assume it's relatively low (< 10MHz)

I would recommend that you do this directly from within an ISR, and not use the RTOS delay functions. Use the RTOS to do other things (like sample the dimmer's position).

While this sort of accuracy is possible with a Salvo task, the problem is that for typical and best cases you'll never see any jitter-related error, but in the worst case (e.g. you have lots of tasks and your switching task is low priority and the delay just expired and the task must be re-enqueued), the jitter could be considerable (and hence noticeable). Though I suppose it would work fine if this task were the highest-priority task ... Hmm ...

My rule of thumb for accurate timing in an embedded system is:

1-99 cycles: Must do it in-line with no interrupts.

100-999 cycles: do it via an interrupt.

1000+ cycles: do it with a task.

You may want to review to see the real-time constraints of a system that needs accurate timing -- may give you some ideas.


Re: Triac phase control for lamp dimmer

PostPosted: Tue Apr 10, 2007 7:37 am
by dsptony
Thanks for the reply. I forgot to mention that I also posted this on the Hi-Tech forum (I’m using their compiler).

I am using the onboard 4MHz oscillator. I think I will try what you suggest and use Salvo for all my other tasks, and handle this one high priority task with my own handler. Maybe once I get more experience I could experiment with running it as a high priority task or think of some other way to do it.