Dimmer - How synchronize PWM with 230V power supply ?

2,150 views
Skip to first unread message

Piotr Pawlak

unread,
Nov 28, 2015, 2:28:32 PM11/28/15
to WebIOPi
Hello again ! :)

I need your's help with dimmer which is controlled by Raspberry PWM. My problem is lack of synchronization PWM with power supply. Unfortunately , I don't have oscilloscope waveforms to show my problem, but I can show my python script and electrical drawings which I use.

Firstly: Electrical drawings.










Pic. 1


Picture 1 presents zero-cross detection circuit R1 - 33K , R2 and R3 - 68K and optocoupler PC814. This give me high signal in Raspberry input, when power supply is equal 0 and I obtain waveforms like in Pic. 2


















Pic. 2







MOC 3021 and BTA16 triac I use to dimming my light bulb. In Pic. 3 is shown MOC3041, but I use MOC 3021.





















Pic. 3

Secondly: Pyhton script.


































Pic. 4

This is one of my python scripts. I use simple commands ( don't look at comment :) ). When input is high then will be run PWM with duty cycle 50. And second script in Pic. 5 - I use in this interrupts.

Pic. 5

I tried use interrupts with falling and rising edge.


So, when I run my script ( Pic. 4 or Pic. 5) my PWM signal doesn't have synchronization with 230V power supply. PWM isn't triggered when it should. I'm angry that I didn't do oscilloscope waveforms. I think that hardware is good but software is bad. I supported with another project where somebody used those elements (MOC 3021 and PC814) and it worked fine, but used ATmega32.


Regards,

Peter.


Lukasz Jakubek

unread,
Nov 30, 2015, 4:11:45 AM11/30/15
to WebIOPi
Hi Piotr,
Don't you think the latency of 'interrupt routine' in Python might be just too big 
and too unpredictable to think about real time task like you expect to implement?  

BR
Lukasz

Lukasz Jakubek

unread,
Nov 30, 2015, 4:51:20 AM11/30/15
to WebIOPi
Moreover - to what I've written below: Why do you expect p.ChangeDutyCycle(dc) would sync PWM output at all? 
It is meant to change duty cycle, not to force output. If you want to have some control you could have start a timer when 
you get zero-cross detection and during the timer open the output triac. Without using PWM apis....

Pete Dudash

unread,
Nov 30, 2015, 11:45:05 AM11/30/15
to WebIOPi
Using 230VAC with PWM is undoubtedly out of the scope of webiopi.  You might not get the answers you want here.

That being said, I can still try giving my two cents.  Triacs are not operated like FETs with PWM.  They are phase-angle controlled which is why you require the zero crossing detector.  The triac connections to AC are not reversible - make sure you get the polarity correct!  Depending on when you turn the triac on after the zero crossing will determine the amount of power delivered to the load (see image below).  I strongly suggest against using the RPi for this control since timing is very important.  The type of load is also important.  Additional care must be taken when driving inductive loads.




Check out this article: http://www.sunrom.com/p/dimmer-module-digital-control-256-steps.  It has some basic theory of operation and diagrams.
This video is also ok.  There is a link with more details in the description: https://youtu.be/_gQw_vtn0VI

Rather than use a separate micro, you could probably design a clever 555 circuit with some sort of resettable monostable multivibrator that is synchronized with the zero crossing.  Then your PWM duty cycle can be use to adjust the timeout.

Please be careful!  You don't want to burn your house down or electrocute anyone!

Piotr Pawlak

unread,
Dec 1, 2015, 4:20:29 PM12/1/15
to WebIOPi
Thanks Lukasz and Pete for answers :) I will buy ATtiny to control my dimmer :) I hope it will work:)

Sergey Podobrey

unread,
Dec 2, 2015, 4:26:59 PM12/2/15
to WebIOPi
You can try to use the Russian chip КР1182ПМ1

Pete Dudash

unread,
Dec 3, 2015, 4:32:48 PM12/3/15
to WebIOPi
Perhaps the less you play with 230VAC mains, the better.  Have a read about proportional SSRs here: https://www.digikey.com/Web%20Export/Supplier%20Content/Crydom_172/PDF/crydom-news-110808.pdf?redirected=1

You probably don't want to use the pulse skipping (burst fire) SSRs since they might cause your lights to flicker or make audible noise.  Or you can make your own as stated earlier.

Reply all
Reply to author
Forward
0 new messages