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: 7
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 640 times

fabiuz7
Posts: 1
Joined: Fri Nov 01, 2019 6:52 pm

Re: ESP32 with Triac

Postby fabiuz7 » 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.

Who is online

Users browsing this forum: No registered users and 12 guests