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.
PWM to MOSFET as ac230 dimmer
Re: PWM to MOSFET as ac230 dimmer
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?
That seems to be an interesting approach. Do you synchronize your PWM with the mains frequency?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: PWM to MOSFET as ac230 dimmer
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.
Index to my micropython libraries.
Re: PWM to MOSFET as ac230 dimmer
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.
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.
Re: PWM to MOSFET as ac230 dimmer
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.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: PWM to MOSFET as ac230 dimmer
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.
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.
Index to my micropython libraries.