logo elektroda
logo elektroda
X
logo elektroda

Problem with ESP32 interrupts originating from the PC817C optocoupler

endriuh28 1530 12
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19389968
    endriuh28
    Level 9  
    Hello, as in the subject, I have a problem with the detection of an interrupt from a PC817C optocoupler.
    The voltage is 3.3V and I have the emitter of the optocoupler (leg 3) connected to the ESP32 with the GPIO35 pin,
    with an external pulldown in the form of a 10K resistor Ω connected to GND.
    I have set this pin as INPUT and the interrupt mode as FALLING.
    The ESP32 detects the interrupt but it is not synchronous, and mostly detects double.

    My ESP32 is a DevKitC ESP-WROOM-32U.

    No problems with the Arduino UNO, it detects correctly,
    But the ESP32 seems to have faster sampling at a higher frequency than the Arduino UNO.

    I think the ESP32 pin voltage of 3.3V is not a problem, as the Arduino UNO has a pin voltage of 5V.

    I tested on my little oscilloscope and at 2V and 10ms the signal is rectangular and varies from 0.16V to 3.2V,
    and when I decrease the time the signal looks more and more like a sine wave,
    when I add a larger resistor the signal sharpens but the voltage floor rises significantly,
    and when I decrease the resistance the signal rounds off and looks more like a sine wave.

    In the function called by the interrupt I have added a check to see if there is a low state on the pin:
    Code: C / C++
    Log in, to see the code
    .
    This caused me to no longer detect interrupts doubly, but they are still not synchronous.

    I ad hoc solved the problem softly with code like this:
    Code: C / C++
    Log in, to see the code
    .

    Is it possible to somehow improve the signal so that at higher sampling frequencies i.e. less time it is more rectangular, and so that there are no problems detecting the interrupt during the descent?
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • #2 19389986
    yego666
    Level 33  
    It seems to me that you would help yourself a lot by inserting some simple gate ( inverter ) with Schmidt input between the optocoupler and the ESP input. This should improve the shape of the optocoupler signal.
    In general, optocouplers are very slow compared to processors and other modern circuits, so you can expect good results from such a treatment.
  • ADVERTISEMENT
  • #3 19390019
    endriuh28
    Level 9  
    yego666 wrote:
    I think you would help yourself a lot by inserting some simple gate ( inverter ) with Schmidt input between the optocoupler and the ESP input. This should improve the shape of the signal from the optocoupler.


    And could you give me some schematic of how to connect this and what gate model to give?
    And whether to leave this resistor?
  • ADVERTISEMENT
  • Helpful post
    #4 19390036
    khoam
    Level 42  
    The GPIO inputs on the ESP32 do not have a Schmitt gate on the input (like the AVR), so any fluctuation in the input voltage in the area between the high and low states can cause the effect you describe and randomly generate interrupts.

    endriuh28 wrote:
    I have ad hoc solved the problem softly with code like this:
    .
    You have written something like a software Schmitt flipper :) But it is better to use an external circuit if you want to achieve higher sampling rates.

    Added after 1 [minute]:

    endriuh28 wrote:
    And whether to leave this resistor?
    .
    This resistor can be left in place. GPIO35 has no internal pull-up or pull-down.
  • Helpful post
    #5 19390056
    yego666
    Level 33  
    Here you go :) .

    I would use a circuit n.p. 74HC14 , which has Schmidt inputs and works from as low as 3V supply.
    A single cube has as many as six inverters, so you can use them for other purposes too.

    Search the internet for "74HC14 pdf" . You will find a description and the layout of the legs of this cube. Cost less than 1 Pln.
  • #6 19390569
    endriuh28
    Level 9  
    I'm running out of space on the board and I don't want to enlarge it because it won't fit into my case.
    Is there perhaps a smaller version of this 74HC14 chip, with one input and output?

    khoam wrote:
    This resistor can be left. GPIO35 has no internal pull-up or pull-down.
    .
    Yes I know, I already implied this with the fact that even though it is INPUT_PULLUP it is INPUT.
  • ADVERTISEMENT
  • Helpful post
    #7 19390637
    yego666
    Level 33  
    There are single gates n.p. here: Link , but you have to buy min. 5 pcs at 1.25pln/piece. A bit expensive.
  • #8 19390673
    endriuh28
    Level 9  
    yego666 wrote:
    There are single gates n.p. here: Link , but you have to buy min. 5 pcs at 1.25pln/piece. A bit pricey.


    I found this chip on Alegro for 1zł.
    And is it perhaps in a THT through-hole housing?

    And if I use this gate, when there is theoretically a high state, i.e. some voltage from PC817
    then there will be a low state behind the gate, did I understand correctly?
    If so, I now have to set it to RISING instead of FALLING mode.

    Of course I am going to use the SMD version anyway when I update the board,
    but in order not to bin the five boards I have, I would make an adapter on a universal board.

    Thank you yego666 , you have helped me a lot, many thanks to everyone for participating in this topic of mine.
  • Helpful post
    #9 19390691
    yego666
    Level 33  
    You make a good combination with the polarity :) .
    Unfortunately the tht version they don't produce :( .
    Make a prototype from one gate of the 74hc14 chip in the tht version.
    This will probably be the easiest way.
    Good luck.
  • #10 19391026
    endriuh28
    Level 9  
    Ok, in that case that's what I'll do, or I'll somehow solder this SMD chip to a universal double sided board, maybe it will fit.
    I'll buy a couple of pieces of this with THT and a couple of pieces with SMD.

    Thanks again for your help yego666 .
  • #11 19397716
    krzbor
    Level 27  
    khoam wrote:
    The GPIO inputs on the ESP32 do not have a Schmitt gate on the input (like the AVR),
    .
    I didn't know that (habit from AVR). And how is it in the ESP8266?
  • #12 19397739
    khoam
    Level 42  
    krzbor wrote:
    khoam wrote:
    The GPIO inputs on the ESP32 do not have a Schmitt gate on the input (like the AVR),
    .
    I didn't know that (habit from AVR). And how is it in ESP8266?
    .
    Same.
  • #13 19402407
    endriuh28
    Level 9  
    Yes, I had a similar problem with the ESP8266 Pro Mini, only there what was different was the source of the PWM signal, so colleague khoam is right.
    At the time I thought the problem was with the circuit I was connecting.

Topic summary

The discussion revolves around issues with detecting interrupts from a PC817C optocoupler connected to an ESP32 (DevKitC ESP-WROOM-32U) via GPIO35. The user experiences asynchronous and double interrupts, which are not present when using an Arduino UNO. Suggestions include using a Schmitt trigger inverter (e.g., 74HC14) to improve signal integrity, as the ESP32 lacks internal Schmitt trigger inputs. The resistor configuration can remain unchanged, and the user is advised to adjust the interrupt mode to RISING if using an inverter. The conversation also touches on the availability of single gate versions of the 74HC14 and the user's plans for board modifications.
Summary generated by the language model.
ADVERTISEMENT