Does anybody know the reason why a GPIO Input Pin (any, tried a lot 14,21,22,32,35,5,4) has a double interrupt when using a optocoupler (TLP281)?
The setup used is the following:
One ESP32 will manage the Output connection to the opto, basically setting High/Low so that the opto switches the ground signal coming from another ESP32 that has the Interrupt Routine on a pin (14 on the pictures). GROUNDS are NOT tied together. In any case, when grounds are tied, the result is the same.
As you can see in the pictures, the Sender ESP32 sends a single pulse and counts it and the Receiver ESP32 with the interrupt pin receives the Interrupt and sends to a queue with a task that reads the queue and prints (a) the count, (b) the tickcount when the int happened and (c) if the signal was high or low.
The Interrupt pin is set to NEGEDGE, pullup enabled (also tested with an additional 10k pullup).
Code: Select all
void pinTaskIn(void *pArg)
io_conf.intr_type = GPIO_INTR_NEGEDGE;
io_conf.pin_bit_mask = (mask<<whichPin);
io_conf.mode = GPIO_MODE_INPUT;
isrQ = xQueueCreate( 100, sizeof( param ) );
if( xQueueReceive( isrQ, ¶m, portMAX_DELAY ))
printf("Count %d lowHigh %d timer %d\n",param.count,param.lowHigh, param.timer);
As a good measure, doubting the initial NEGEDGE setup was wrong(?), we again set the int type to NEGEDGE.
The result is that for a Single activation of the optocoupler the Interrupt routine has 2 interrupts, one for a Low and another for a High when it is clearly defined only NEGEDGE.
The worst part is that it is not consistent, most of the times it has two interrupts but randomly it has only one (second print screen Count 3).
I have tried Hardware setups like 1.5 K pullup to 300K pullup. No change. A 1uf Cap. Same result.
The sending routine is simple but i attach it so as to have no doubts about the code.
Code: Select all
void pinTaskStep(void *pArg)
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.pin_bit_mask = (mask<<defs->elpin);
io_conf.mode = GPIO_MODE_OUTPUT;
Also for good measure a Logic Analyzer was used and it sees only 1 pulse. Please note that the delay is 100ms and the Logic screen has no pulses after 300ms or more.
Also from the interrupt we get that there is Low int and then a High int 100ms after the first. No idea how.
This experiment as done to confirm that a Electric Meter which sends a signal via an optocoupler is not a fault. A Logic Analyzer was used with the meter and had the same results as the experiment with only one pulse registered but 2 ints in the ESP32. I originally thought it was a "noise interference" in the Electric Meter but in our "lab" the result is the same with a simple setup.
Any ideas or suggestions are welcomed.