ESP32 with Triac
ESP32 with Triac
Hello.
I've spend most of this week trying to find a working code for ESP32 ( not IDF ) which would works for trigering a triac ( PWM or so ) in a meaning of regulating the output ( dimming a lamp or so ) but NO LUCK AT ALL.
Most of the code I have found is about Arduino or ESP8266 with incompatible libraries or not working pieces of code for ESP32.
I've tried to implement the hardware timer of ESP32 for the trigering but seems like I am missing something.
Yet still banging against the wall and not sure where to begin.
I am using as a Triac - BTA41 with optocoupler MOC3063 and Zero Cross detector optocoupler 4N25 - seems like I am detecting the zero cross fine, but yet something is wrong with the timers.
Please, if someone have a working fine piece of code with ESP32 for dimming AC loads with triacs - share.
Thank You in advance.
P.S. I am attaching the circuit I have designed for my needs.
I've spend most of this week trying to find a working code for ESP32 ( not IDF ) which would works for trigering a triac ( PWM or so ) in a meaning of regulating the output ( dimming a lamp or so ) but NO LUCK AT ALL.
Most of the code I have found is about Arduino or ESP8266 with incompatible libraries or not working pieces of code for ESP32.
I've tried to implement the hardware timer of ESP32 for the trigering but seems like I am missing something.
Yet still banging against the wall and not sure where to begin.
I am using as a Triac - BTA41 with optocoupler MOC3063 and Zero Cross detector optocoupler 4N25 - seems like I am detecting the zero cross fine, but yet something is wrong with the timers.
Please, if someone have a working fine piece of code with ESP32 for dimming AC loads with triacs - share.
Thank You in advance.
P.S. I am attaching the circuit I have designed for my needs.
Re: ESP32 with Triac
Hi!
Make interrupt to zerocross detect. in this interrupt setup timer interrupt.
In timer interrupt make enough time pulse to triac,
or set the triak on, and next zerocross interrupt switch the triak off
https://techtutorialsx.com/2017/10/07/e ... nterrupts/
Make interrupt to zerocross detect. in this interrupt setup timer interrupt.
In timer interrupt make enough time pulse to triac,
or set the triak on, and next zerocross interrupt switch the triak off
https://techtutorialsx.com/2017/10/07/e ... nterrupts/
Re: ESP32 with Triac
Hello.
As I've mentioned above - it's all done, but not working good.
I've pass this tutorial many times, but actually it's just a chunk of code which is in very raw format, and somewhat the reality with triac seems like a whole different story.
That's why I am asking for a tested library or code for ESP32.
As I've mentioned above - it's all done, but not working good.
I've pass this tutorial many times, but actually it's just a chunk of code which is in very raw format, and somewhat the reality with triac seems like a whole different story.
That's why I am asking for a tested library or code for ESP32.
Re: ESP32 with Triac
Looking at the schematic, it seems as if you may be close to under driving the MOC3063. It has a 1.2V drop across the LED and requires a minimum of 5mA to trigger. The ESP32 has a Voh of 2.64V with load. (2.64-1.2)/200ohm = 7.2mA. Above spec, but barely. I would drop the resistor to 150ohm to ensure something close to 10mA.
Also, you say "Most of the code I have found is about Arduino..." Why doesn't this work? What framework are you using to build your code?
Including your code, at least a relevant snippet, would be useful if you want help.
Tom
Also, you say "Most of the code I have found is about Arduino..." Why doesn't this work? What framework are you using to build your code?
Including your code, at least a relevant snippet, would be useful if you want help.
Tom
Re: ESP32 with Triac
I found this library https://github.com/fabiuz7/Dimmable-Light-Arduino
But it didn't work for me. Then I tried to write my own code. And that didn't work as well. It should have. Then I came across a post about the Rev. 0 ESP32 chip. I then tried my own code again on a module with a Rev 1 processor. It worked. I then tried the above library again and it also worked.
So the reason it may not have worked for you might be because of the chip revision, if you have a rev 0 chip.
But it didn't work for me. Then I tried to write my own code. And that didn't work as well. It should have. Then I came across a post about the Rev. 0 ESP32 chip. I then tried my own code again on a module with a Rev 1 processor. It worked. I then tried the above library again and it also worked.
So the reason it may not have worked for you might be because of the chip revision, if you have a rev 0 chip.
Re: ESP32 with Triac
I can't access my regular account here on this computer so I had to re-register under a new name. So my last, and this post, will likely be delayed since it has to be approved.
I have been designing a new product with the ESP32 for a work. Initially I tried to get phase control to work, and I did. And I got it to work very well. But in the end I will not be using phase control for the product. Instead I will be using the triac to turn on full half wave pulses. The application is for heating so there is no real need for phase control. Although that is how the previous products we made have worked. Most of our products have phase control for motor speed control, or phase control for lighting applications.
One thing I found with the ESP32 was that I got multiple interrupts on a zero crossing. The risetime of the zero crossing detection circuit is not very fast. And the ESP32 does not seem to have a Schmitt trigger input (hysteresis) and I had to do a couple of things to eliminate the unwanted additional triggering.
I have been designing a new product with the ESP32 for a work. Initially I tried to get phase control to work, and I did. And I got it to work very well. But in the end I will not be using phase control for the product. Instead I will be using the triac to turn on full half wave pulses. The application is for heating so there is no real need for phase control. Although that is how the previous products we made have worked. Most of our products have phase control for motor speed control, or phase control for lighting applications.
One thing I found with the ESP32 was that I got multiple interrupts on a zero crossing. The risetime of the zero crossing detection circuit is not very fast. And the ESP32 does not seem to have a Schmitt trigger input (hysteresis) and I had to do a couple of things to eliminate the unwanted additional triggering.
Re: ESP32 with Triac
Hey Rudy12 !
Thank You very much for your help ! <3
I am definitely going to try this !
About the Schmitt trigger input.. - I didnt knew this.
With this board I am aim to manage the speed of a small ( 30W ) motor, and 1 kW heater.
So. will this reflect badly on my design ?
I mean - what do I need to rework on my schematic in order to make it works well ?
Any suggestions is more than apprecated.
Thank You very much for your help ! <3
I am definitely going to try this !
About the Schmitt trigger input.. - I didnt knew this.
With this board I am aim to manage the speed of a small ( 30W ) motor, and 1 kW heater.
So. will this reflect badly on my design ?
I mean - what do I need to rework on my schematic in order to make it works well ?
Any suggestions is more than apprecated.
Re: ESP32 with Triac
Sorry for not answering sooner. I don't come here often. I am just beginning to get into working with the ESP32. I have mainly used the ESP8266 until now.
https://github.com/fabiuz7/Dimmable-Light-Arduino is the library I first tried (but couldn't get to work on the rev. 0 part). I didn't use it in the end, but it is worth looking at.
The application I have is for heating and I first thought I was going to use phase control. But I decided to go with a form of duty cycle control based on full half wave increments. I decided to use 100 as my base. For 25% power I use 25 half wave pulses and 75 pulses off before repeating the pattern. I think I would have been OK if I had used the first 25 cycles on and then 75 cycles off, but I wanted to distribute the on/off cycles more.
What I did was have ten segments in the 100 half cycles. If I wanted 10% power I would have 10000000000 repeated 10 times. If I needed 12% power the routine does 1100000000.1100000000.100000000.100000000.100000000...
The reason I am not using phase control is that the application doesn't need it (heating). The current product we sell does use phase control and you can hear the heat panels buzzing. The chopped up waveform creates a lot of harmonics and the higher harmonics are easier to hear compared to the original sine wave. Another reason I decided against phase control is that I don't have to put in an inductor for radio frequency noise suppression. All our products have a triac circuit like in your schematic but it also has a inductor in series with the load and a capacitor across the load. So by not using phase control I make a more "friendly" circuit and reduce the cost of the implementation. If I had a motor to control I would have to add the additional RF suppression parts for a commercial product. You may find that for your particular application it may not be necessary.
The one concern that I have with your schematic is the zero crossing detection. It really is half wave detection and you will have a slight skewing. I'm concerned that you might end up with each second period being different than the first. This produces a DC offset and AC motors don't really like that.
With phase control there can be some instability with short trigger pulses when operating near or at full power. Motors can start to growl. To prevent that you should either just put a steady dc on the optocoupler, or increase the pulse time so that there is a longer trigger period. This problem may or may not happen for you. It depends on the motor used.
As far as motors. Most AC induction motors are not designed for reduced speed operation. Also, when you use phase control to reduce the speed of a motor, the current drawn by the motor goes up. Reduced speed operation creates higher current through a significant portion of the speed range. The average current could be 30% more than the full speed running current. Just think about a motor at startup. It draws a higher current until it gets to the full speed. Running a motor at reduced speed makes it draw more current as it is trying to get in sync with the line frequency.
https://github.com/fabiuz7/Dimmable-Light-Arduino is the library I first tried (but couldn't get to work on the rev. 0 part). I didn't use it in the end, but it is worth looking at.
The application I have is for heating and I first thought I was going to use phase control. But I decided to go with a form of duty cycle control based on full half wave increments. I decided to use 100 as my base. For 25% power I use 25 half wave pulses and 75 pulses off before repeating the pattern. I think I would have been OK if I had used the first 25 cycles on and then 75 cycles off, but I wanted to distribute the on/off cycles more.
What I did was have ten segments in the 100 half cycles. If I wanted 10% power I would have 10000000000 repeated 10 times. If I needed 12% power the routine does 1100000000.1100000000.100000000.100000000.100000000...
The reason I am not using phase control is that the application doesn't need it (heating). The current product we sell does use phase control and you can hear the heat panels buzzing. The chopped up waveform creates a lot of harmonics and the higher harmonics are easier to hear compared to the original sine wave. Another reason I decided against phase control is that I don't have to put in an inductor for radio frequency noise suppression. All our products have a triac circuit like in your schematic but it also has a inductor in series with the load and a capacitor across the load. So by not using phase control I make a more "friendly" circuit and reduce the cost of the implementation. If I had a motor to control I would have to add the additional RF suppression parts for a commercial product. You may find that for your particular application it may not be necessary.
The one concern that I have with your schematic is the zero crossing detection. It really is half wave detection and you will have a slight skewing. I'm concerned that you might end up with each second period being different than the first. This produces a DC offset and AC motors don't really like that.
With phase control there can be some instability with short trigger pulses when operating near or at full power. Motors can start to growl. To prevent that you should either just put a steady dc on the optocoupler, or increase the pulse time so that there is a longer trigger period. This problem may or may not happen for you. It depends on the motor used.
As far as motors. Most AC induction motors are not designed for reduced speed operation. Also, when you use phase control to reduce the speed of a motor, the current drawn by the motor goes up. Reduced speed operation creates higher current through a significant portion of the speed range. The average current could be 30% more than the full speed running current. Just think about a motor at startup. It draws a higher current until it gets to the full speed. Running a motor at reduced speed makes it draw more current as it is trying to get in sync with the line frequency.
Re: ESP32 with Triac
@Rudy,
Good choice in using the method you used for the heater. Much simpler and much more reliable.
Tom
The zero crossing opto is driven by a bridge rectifier, so it should be full wave and will turn on and off at approximately the same voltage before and after the crossing, so, barring any phase shift in the transformer, it should be relatively easy to predict exact center by measuring the width. However, it doesn't filter out noise near zero so a reliable detection would require a bit more sophistication in the SW (ie, reject erroneous crossings and use the SW predicted one instead).The one concern that I have with your schematic is the zero crossing detection. It really is half wave detection and you will have a slight skewing.
Good choice in using the method you used for the heater. Much simpler and much more reliable.
Tom
Re: ESP32 with Triac
For dimming purposes, you'll need a non-zero cross triac driver like MOC3023. MOC3063 won't work.
Who is online
Users browsing this forum: No registered users and 81 guests