PWM to MOSFET as ac230 dimmer

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
sachin213
Posts: 2
Joined: Mon Nov 12, 2018 4:27 pm

PWM to MOSFET as ac230 dimmer

Post by sachin213 » Wed Nov 14, 2018 4:48 pm

hi, i have written a python script on esp-01 to generate pwm signal to a gpio. so that works perfectly with LED. but when i connect that gpio to a MOSFET (IRF840) through optocoupler as a Ac230v dimmer, sometimes it works, but sometimes the flie system crashes and stops working. when i listdir() it prints garbage. so i have to copy the .py file or sometimes have to reflash micropython. guess this is due to high voltage spikes or due to kind of induction the ROM corrupts.
has anybody came across this situation? any workaround?
thanks.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: PWM to MOSFET as ac230 dimmer

Post by Roberthh » Wed Nov 14, 2018 5:29 pm

Can you show the schematics of your circuit? The optocoupler should block any backward influence.
That seems to be an interesting approach. Do you synchronize your PWM with the mains frequency?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: PWM to MOSFET as ac230 dimmer

Post by pythoncoder » Thu Nov 15, 2018 9:04 am

To get the benefit of opto coupling the two sides of the circuit need to be electrically isolated from each other. In other words the circuit driving the MOSFET gate needs to be powered from a separate power source from that of the ESP8266.
Peter Hinch
Index to my micropython libraries.

sachin213
Posts: 2
Joined: Mon Nov 12, 2018 4:27 pm

Re: PWM to MOSFET as ac230 dimmer

Post by sachin213 » Fri Nov 16, 2018 1:24 am

hi i have used the attached circuit diagram
https://www.google.lk/imgres?imgurl=htt ... mrc&uact=8

tried using separate power supply and guess no need of syncing when using mofet instead of triac.
thanks for the replies.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: PWM to MOSFET as ac230 dimmer

Post by Roberthh » Fri Nov 16, 2018 6:52 am

In principle the circuitry looks OK. It is hard to guess which backward interference can be cause from the AC side. At which frequency do you run the PWM, and do you carefully maintain the isolation? Please bear in mind, that fast switched lines also create a substantial electromagnetic field of large bandwidth, which may couple into the micro-side. That gets worse with longer cables and loads which are not only resistive.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: PWM to MOSFET as ac230 dimmer

Post by pythoncoder » Fri Nov 16, 2018 8:07 am

If isolation is maintained the most likely cause is high dv/dt on the MOSFET drain generating radiated RF interference.

The nature of the circuit makes this hard to check with an oscilloscope unless you can run the whole thing from a 1:1 isolation transformer (where to connect the 'scope ground lead?). If you connect the 'scope ground lead to mains earth the waveform will be a mess owing to the effect of the bridge rectifier but you should be able to measure rise and fall times.

I would expect the fall time to be relatively slow as the MOSFET turn-on speed will be limited by the available current (~3mA) and the gate-source and Miller capacitances. But turn-off might be fast as the opto isolator could dump the charge rapidly. The answer may be a resistor between drain and load and a capacitor between load and source. These would need to be mounted close to the MOSFET. The capacitor and load resistance would determine dv/dt when the MOSFET turns off, with the resistor limiting the current when the device turns on.

If your switching frequency is high and your turn-on time is slow you may need to consider power dissipation in the MOSFET.

What type of lamp are you using? I don't know how the electronics in CFL or LED lamps respond to running from chopped DC, or the nature of the load they present to the circuit. In the days of filament lamps dimmers were synchronous to the mains with a triac turning on at a variable point in the cycle and turning off when current passed through zero. I've no idea whether modern commercial dimmers work in this way.
Peter Hinch
Index to my micropython libraries.

Post Reply