-
Notifications
You must be signed in to change notification settings - Fork 13.3k
nodeMCU + ArduinoIDE zero crossing #1483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
if you get the interrupt before the real one it must be some noise on the line. keep in mind the the WiFi and OS from the SDK, |
p.s. As been mentioned elsewhere the standard ESP wifi blocks on sending packets so you should use the newer Async library. #1430 |
@drmpf looking at the code above, can't the triac be controlled by the PWM driver? So you do not need to delay and switch in the callback. If only one interrupt is attached, I have measured about 2-3us delay between the event and the time the callback is called. At 50Hz that should be OK :) |
Maybe if not the PWM driver, then use timer0 or timer1 to control switching and not delay at all in the callback. |
@me-no-dev do you have an example? @brunoudi have you figured a reliable way to detect zero crossing? Is there a way to add timer intervals? |
https://gist.github.com/me-no-dev/2e185a909000f6ac9605 |
hi @me-no-dev , the links you passed,it is implemented in ESP?, I don't recognize GPOS or GPI term in the code |
yes that is ESP :) it's direct register manipulation (if you look in the core files you will see many things like that) |
Interesting discussion, but closing per #3655 . |
I sugest this circuit: |
You could use multitask (free RTOS) with ESP. |
I'm trying to make a dimmer with nodeMCU and ArduinoIDE, but I'm having a problem with the zero cross detection.
Considering 60hz, i would get a interrupt every 8,33 ms, but in 10% of the cases I get a interrupt at 7,86ms and then another at 0,47ms.
Those "mistakes" is causing the lamp to flicker.
My code is below, as my schematic.
I would like to hear your opinion and sugetions.
Thanks.
const int pulsePin = D2; //pin to pulse the triac
cont inst zcPin = D1; //pin to zero cross detection
int tempo = 0; //time to wait to send the pulse in microseconds
void zeroCrossing() {
if (tempo == 0) {
digitalWrite(pulsePin, LOW);
}
else {
delayMicroseconds(tempo);
digitalWrite(pulsePin, HIGH);
delayMicroseconds(20);
digitalWrite(pulsePin, LOW);
}
void setup() {
Serial.begin(115200);
pinMode(pulsePin, OUTPUT);
pinMode(zcPin, INPUT);
attachInterrupt(digitalPinToInterrupt(zcPin), zeroCrossing, FALLING);
}
void loop () {

int temp;
if (Serial.available()) {
temp = Serial.parseInt();
if (temp != 0) {
tempo = temp;
}
}
}
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: