PDA

View Full Version : PWM with a PIC



The Master
- 28th September 2007, 19:06
Hi. I know PICs have some kind of built in PWM thing for a few pins but im trying to to PWM without using that (so it works on all pins). I have been told that i need a loop to turn an output pin on and off rapidly but aparently, if im dealing with mains circuits (eg a dimmer switch) then i need to sync it with the mains sine wave.

Do i actually need to sync it?
If so how?

Is this the worst possible way of doing it and should i try something else? lol

mister_e
- 28th September 2007, 22:55
Yes you'll need to synch it or you're going to see some weid blinky stuff. What you need is a spare input who will sense the AC main. Then each Zero Crossing, you refresh your dimmer outputs.

For safety reason, you want to use an optoisolator between the MAIN and your circuit. Anything like LTV-814,PS2505 will work.

If you decide to use Your power supply transformer, you may need to calibrate it in software to compensate the phase difference between the primary and secondary.

DynamoBen
- 29th September 2007, 01:14
Normally PWM is used when you want to dim a DC load. In your case you are trying to dim an AC load, this is done very differently. In short AC dimming requires a zero cross sense, and an interrupt timer.

For more detail on how AC dimming works check out this website:
http://www.dv-fansler.com/Computer%20Lights/dimmers.htm

NOTE: You can't dim inductive loads with this method, only resistive loads like light bulbs.

The Master
- 3rd October 2007, 08:58
Thanks. ill have to check that link when i get home because its blocked at work.

Ive been thinking about some LED lighting projects too. How would i dim those? I would assume its more or less the same idea but LEDs dont glow for a while after the power goes off like bulbs so wouldnt they just flash rapidly?

Is it really complicated to dim things like transformers? Ive seen lighting controllers do it before

mister_e
- 3rd October 2007, 14:50
Dimming theory is almost always the same, the driver circuit may need to be changed.

Do a search for snubber, Inductive load dimmer (dimming/driving), snubberless Triacs.

For LEDs... don't worry, you don't need any synch. Just a high enough frequency will work.