I have an ESP-07 with NodeMCU firmware connected to a dimming module with a zero-crossing pin.
The current frequency should be 50Hz, which means that the time between two zero crossing should be 10ms, ~10000 microseconds.
However the time between two interrupts is sometimes correct, but often is about ~450 microseconds.
What's the catch? I use tmr to measure time
Here is the code:
gpio.mode(2, gpio.INPUT) gpio.mode(5, gpio.OUTPUT) t = tmr.now(); counter = 0; local function zc_callback(level, pulse) counter = counter + 1; counter = counter % 200; if(counter == 1) then print(tmr.now() - t); end t = tmr.now(); end gpio.trig(2, "up", zc_callback)
Thank you, I try to figure this for some time, it affects my light bulbs which blink instead of dimming.