-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
Hardware:
Board: ESP32 Dev Module
Core Installation version: 1.0.2
IDE name: Arduino IDE
Flash Frequency: 40Mhz
PSRAM enabled: no
Upload Speed: 921600
Computer OS: Windows 10
Description:
I'm building a simple triac based dimmer using an AC Light Dimmer from RoboDyn module and an ESP32 Wroom dev board. It worked on an ATEGA328 but fails with the ESP32.
GPIO4 is connected to the Zero Crossing output of the AC module
GPIO5 is connected to the Gate input of the AC module
the AC module is powered by the 3V3 regulator of the ESP32 dev board
As shown on the oscilloscope screenshot below, why is the interrupt triggered twice ?
The issue is the same if I use different GPIO pins for the interrupt and gate.
This behavior was not happening with a Arduino Nano, I wanted to replace the nano with the ESP32
Sketch: (leave the backquotes for code formatting)
const byte phaseCtrl = 5;
const byte interruptPin = 4;
const byte ledPin = 2;
int dimming = 10;
void setup() {
Serial.begin(115200);
pinMode(phaseCtrl, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT);
attachInterrupt(digitalPinToInterrupt(interruptPin), zero_crosss_int, RISING);
}
void loop() {
}
void zero_crosss_int() // function to be fired at the zero crossing to dim the light
{
int dimtime = (75 * dimming); // For 75 uS for 50Hz signal (100Hz zc) in 128 steps of 75 uS each
delayMicroseconds(dimtime); // Off cycle
digitalWrite(phaseCtrl, HIGH); // triac firing
delayMicroseconds(10); // triac On propagation delay (for 60Hz use 8.33)
digitalWrite(phaseCtrl, LOW); // triac Off
delayMicroseconds(10); // triac On propagation delay (for 60Hz use 8.33)
digitalWrite(phaseCtrl, HIGH); // triac firing
delayMicroseconds(10); // triac On propagation delay (for 60Hz use 8.33)
digitalWrite(phaseCtrl, LOW); // triac Off
delayMicroseconds(10); // triac On propagation delay (for 60Hz use 8.33)
digitalWrite(phaseCtrl, HIGH); // triac firing
delayMicroseconds(10); // triac On propagation delay (for 60Hz use 8.33)
digitalWrite(phaseCtrl, LOW); // triac Off
delayMicroseconds(10); // triac On propagation delay (for 60Hz use 8.33)
digitalWrite(phaseCtrl, HIGH); // triac firing
delayMicroseconds(10); // triac On propagation delay (for 60Hz use 8.33)
digitalWrite(phaseCtrl, LOW); // triac Off
delayMicroseconds(10); // triac On propagation delay (for 60Hz use 8.33)
digitalWrite(phaseCtrl, HIGH); // triac firing
delayMicroseconds(10); // triac On propagation delay (for 60Hz use 8.33)
digitalWrite(phaseCtrl, LOW); // triac Off
delayMicroseconds(10); // triac On propagation delay (for 60Hz use 8.33)
}