ESP32 with Triac

TomWS1
Posts: 21
Joined: Wed May 01, 2019 2:50 pm

Re: ESP32 with Triac

Postby TomWS1 » Sun May 19, 2019 12:02 pm

Ristridin wrote:
Sat May 18, 2019 7:47 pm
For dimming purposes, you'll need a non-zero cross triac driver like MOC3023. MOC3063 won't work.
Good catch!

Yordan
Posts: 10
Joined: Tue Aug 28, 2018 10:58 am

Re: ESP32 with Triac

Postby Yordan » Mon May 20, 2019 11:43 am

Oh.. why ? The circuits I am finding around point toward 3063.. I am a new in this stuff, so please explain it to me if possible.

Ristridin
Posts: 8
Joined: Sat May 18, 2019 7:38 pm

Re: ESP32 with Triac

Postby Ristridin » Mon May 20, 2019 6:06 pm

There's of course tons of in-depth information on the internet, so let's keep it simple:
I would say the default way of light-dimming is leading edge trimming.
If we would e.g. dim at 50%, we cut-off the first half of the half-sine.
In other words, we ignite the triac half way the (half)sine wave.
At 50Hz, the whole sinewave duration is 1/50 = 20 milliseconds.
A half sinewave (positive or negative) duration is 10 mseconds.
Igniting half way means: ignite at 5 mseconds after zero crossing.

That's why you need a random-phase triac driver (like moc3023): we don't want to ignite at zero crossing (like moc3063), but (in this example) 5 ms later.
summarizing: led in 4N25 start emitting light just after zero crossing, generating an interrupt at the ESP32.
This interrupt starts a counter, and after 5 ms the ESP generates an ignite pulse for the moc-triac.

Hope this explains.

Yordan
Posts: 10
Joined: Tue Aug 28, 2018 10:58 am

Re: ESP32 with Triac

Postby Yordan » Mon May 27, 2019 6:44 am

Good lords. I haven't event think about this. So my design is generally flawed. Thank You very much !

TomWS1
Posts: 21
Joined: Wed May 01, 2019 2:50 pm

Re: ESP32 with Triac

Postby TomWS1 » Mon May 27, 2019 11:21 am

Yordan wrote:
Mon May 27, 2019 6:44 am
Good lords. I haven't event think about this. So my design is generally flawed. Thank You very much !
You can easily replace the MOC3063 with a MOC3023, they are pin compatible.

Yordan
Posts: 10
Joined: Tue Aug 28, 2018 10:58 am

Re: ESP32 with Triac

Postby Yordan » Wed May 29, 2019 9:32 am

Yep. Will report in a week or two how it went. :)

jainhemendrah
Posts: 1
Joined: Fri Apr 05, 2019 4:47 am

Re: ESP32 with Triac

Postby jainhemendrah » Wed Jun 05, 2019 1:49 am

Dear All,
Look at the below code, it is Phase controlled. But it does not work.



//============================================================================================================
// setup code snippet
//============================================================================================================

attachInterrupt(digitalPinToInterrupt(ZCD_INT), zero_cross_detect, FALLING);

timer = timerBegin(0, 80, true); // Timer pre-scaled to 1usec
timerAttachInterrupt(timer, &dim_check, true);
timerAlarmWrite(timer, 1000, true); // 1ms; timer for testing purpose
timerAlarmEnable(timer);

----------------------------------------------------------------------------------------------




//============================================================================================================
// INTERRUPT FUNCTIONS - TIMER AND ZCD
//============================================================================================================

///*Timer Interrupt Function used to trigger the triac for Dimming*/
void IRAM_ATTR dim_check()
{
/*For Dimmer */
if (zero_cross == true)
{
if (dim_value >= dimming) // 'dimming' is controlled by USER: 0 to 9
{
portENTER_CRITICAL_ISR(&timerMux);
digitalWrite(DIMMABLE_TRIAC1, LOW); // turn on Triac
dim_value = 0; // reset time step counter
zero_cross = false; // reset zero cross detection
portEXIT_CRITICAL_ISR(&timerMux);
}
else
{
dim_value++; // increment time step counter
}
}
}

//--------------------------------------------------------------------------------------------------------------

/*ZCD Interrupt Function*/
void IRAM_ATTR zero_cross_detect()
{
portENTER_CRITICAL_ISR(&timerMux);
digitalWrite(DIMMABLE_TRIAC1, HIGH); // turn on Triac
dim_value = 0; // reset time step counter
zero_cross = true; // reset zero cross detection
portEXIT_CRITICAL_ISR(&timerMux);
}


---------------------------------------------------------------------------------------------------------

HARDWARE : ESP-WROOM32
OPTO BASED BASED ZCD HARDWARE (see attached diagram)
AC Frequency : 50HZ, 230V


FOLLOWING ARE THE ISSUES:
-------------------------

1. Zero Cross Detector Interrupts are generated for multiple times : 33usecs, 1.3ms and 8.7ms. How to avoid such extra interrupts ? I need interrupt only for 8.7ms
(see attached diagram)


Any Input in this direction would be great...I am using ESP32-Arduino for programming.
Attachments
ESP32-ZCD-details.png
ESP32-ZCD-details.png (369.22 KiB) Viewed 12455 times

fabianoriccardi
Posts: 10
Joined: Fri Nov 01, 2019 6:52 pm
Location: Italy
Contact:

Re: ESP32 with Triac

Postby fabianoriccardi » Fri Nov 01, 2019 7:07 pm

Hi all,
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.
Finally I can say that this library is working also for ESP32 rev0, (thanks -rudy-). Also thanks to mention an alternative way to control a electrical heating appliance through full lenght sinusoidal semi-period , avoiding that annoying buzzy sound.
Find me on GitHub :geek:

ManicPinBender
Posts: 1
Joined: Thu Sep 01, 2022 2:09 pm

Re: ESP32 with Triac

Postby ManicPinBender » Thu Sep 01, 2022 2:29 pm

Ristridin wrote:
Mon May 20, 2019 6:06 pm
There's of course tons of in-depth information on the internet, so let's keep it simple:
I would say the default way of light-dimming is leading edge trimming.
If we would e.g. dim at 50%, we cut-off the first half of the half-sine.
In other words, we ignite the triac half way the (half)sine wave.
At 50Hz, the whole sinewave duration is 1/50 = 20 milliseconds.
A half sinewave (positive or negative) duration is 10 mseconds.
Igniting half way means: ignite at 5 mseconds after zero crossing.

That's why you need a random-phase triac driver (like moc3023): we don't want to ignite at zero crossing (like moc3063), but (in this example) 5 ms later.
summarizing: led in 4N25 start emitting light just after zero crossing, generating an interrupt at the ESP32.
This interrupt starts a counter, and after 5 ms the ESP generates an ignite pulse for the moc-triac.

Hope this explains.
Hi Ristridin, hi all other also knowledgable in trailing edge phase controllers,

sorry for derailing this old thread, but as an interested newcomer with a lot of half knowledge, I couldn't resist to try to get your attention. You seem to be knowledgable in the area of phase control circuits and I want to dive a bit deeper into this topic, but I might need a nudge in the right direction.

To keep it short, I want to dimm a LED filament light, which isn't meant for dimming. After reading through a ton of material (blog posts, introduction articles, the very valuable german wiki page and some some stuff more...) I came to the conclusion I would need a trailing edge phase control to not to mess around with the capacitor power supply integrated in the light bulb. I hope I am not completely wrong here.

As you gave recommendations for triacs I hoped you could point me to an explanation, a schematic and BOM for a trailing edge phase controller I could utilize with an ESP32.

Your advice is really appreciated.
Thanks in advance!
-----------------------------------------------------------------------------
Whatever it takes, let's dig down this rabbit hole.

ESP_Sprite
Posts: 9709
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 with Triac

Postby ESP_Sprite » Fri Sep 02, 2022 12:49 am

You might not be able to dim it at all, dependent on the power supply inside the lamp. If it's a capacitive dropper combined with some sort of current regulator IC, the current regulator IC will try to keep the current down the LEDs the same as you attempt to dim them down. This happens up to the point there's not enough voltage in the dropper cap, at which point regulation fails and the brightness will go down fast. As you only have a small range of voltage where you get proper dimming, a difference of a few volt in your 230V supply will get a lot of light difference, meaning the lamp will flicker.

Who is online

Users browsing this forum: Bing [Bot] and 79 guests