# Triac control of AC power using a pic

#### rob_croxford

Aug 3, 2010
262
Hi all.

My last project was to control the amount of DC power delivered to a load using PWM. I am now trying to use a pic to control AC power.

I am in the process of writing a program (in C language) to control the gate pin on a triac that in turn controlls the amount of AC power delivered to a load. I suppose its prity much digital Phase control. The load is resistive, a heater to be precise, and the AC voltage is 240 Mains 50Hz. I already have the circuit built and it is tested using a pwm (i know this will not control the AC however it does aid in showing that the circuit works). Basically the output from the pic will go to a mosfet which will go into an opto-isolator and to the triac. in order to gain phase control i will need to send information back to the pic at the zero crossing points. The Pic also has a variable DC input of 0-10V that controls the AC power.

Basically i will explain my idea for accomplishing this and i would really appreciate it if i got some feedback or any of your own ideas.

I will read from the Pics ADC (i currently working with the PIC12f683) and this value will either;

1) determin from a lookup table (not sure how to create a look up table, but it seems like a good idea, any help on that would be great) what delay needs to be used in order to fire the triac in the right place. The timeing will be over 10ms (half a Full wave cycle) and will be triggered at each zero crossing point. so for instance for 10% power to the load the delay will be 9ms and a pulse will then be sent from the pic to the Triac. relativly simple i know however i am having quite a few problems trying to use this method.

2) my second idea was to take the ADC value and multiply it but the smallest delay gap (10ms/256) to find the correct delay for that ADC value.
for instance;
Delay = J*(39.215);
Delay_us(Delay);
Pic output high;
Delays_us(100);
Pic output low;

Im just wondereing if i am overcomplicating this problem and whether anyone has any feedback as to whether my solution will work or whether there is a simpler solution?

Any ideas would be very welcome.

Cheers,

Rob

#### (*steve*)

##### ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,507
What I would do, since you have to detect the zero crossing points is to calculate the time between them and use that to determine the various delays.

Probably not ever going to be needed in this application, but the ability for it to be independent of mains frequency means you can share the code with others without having to worry if they have 50Hz or 60Hz power (or 400Hz if they're on an aircraft).

I'd kinda be surprised if such code was not already written and available on the net already.

A trick is not to turn on the triac either too early or too late in the half cycle. If too early, it may not latch on, if too late you may accidentally trigger the entire following half cycle (for a given design, it would be hard to have both fault modes)

If you have access to Silicon Chip October 2010, one of their projects is a lighting controller. The code is not available until next month, but both it and parts of the circuit diagrams may be of use. I'm not sure it will be useful enough to go to any great lengths to get a copy though.

Replies
7
Views
497
Replies
0
Views
554
Replies
4
Views
1K
Replies
27
Views
7K
R
Replies
11
Views
2K
ehsjr
E