Page 1 of 1

Detect presence of square wave

Posted: 25 May 2023, 16:40
by mackowiakp
I need to detect the presence of a square wave with a frequency of about 1 kHz on the GPIO input.
If such a square wave appears, I want to send SendToHTTP to Domoticz and also if it disappears, send SendToHTTP to Domoticz as well.
Of course, I can assemble an integrating circuit on an operational amplifier, but I don't want to solder.
Is it possible to do it somehow using rules using e.g. "input switch" by setting the "De-bounce" parameter appropriately?
Any idea?

Re: Detect presence of square wave

Posted: 25 May 2023, 17:18
by TD-er
You could perhaps use the pulsecount plugin and then look at the counted frequency.
With the Interval of such task set to 1 sec, the "count" will be very close to a real frequency counter.

Preferrably use an ESP32 for this as the pulsecount is then done in hardware, not in software as on the ESP8266.

Re: Detect presence of square wave

Posted: 25 May 2023, 17:35
by mackowiakp
Or to use a capacitor connected to GPIO and GND. If ESP32/8266 has Schottky like characteristc.
Does it?

Re: Detect presence of square wave

Posted: 25 May 2023, 21:17
by TD-er
I'm not sure what you'd expect from adding a capacitor?
Do you expect it to act like a simple DA converter or high-pass filter?

Re: Detect presence of square wave

Posted: 26 May 2023, 00:26
by mackowiakp
Yes.
This square wave is fed to the GPIO input through an optocoupler because it has 24V and comes from a completely different device with its own power supply. Hence the capacitor eg 680 nF "integrates" the square wave to DC voltage. Approximately, of course.
The delay introduced by such a system is in this case irrelevant to me. If it's even 2-3 seconds, it's OK.
Only for it to work properly, the input must have a voltage hysteresis characteristic - like Schottky gates.
I can't find an answer anywhere whether GPIO configured as an input has such characteristics.
I think so. But I couldn't find confirmation.

Re: Detect presence of square wave

Posted: 26 May 2023, 01:22
by TD-er
Why not simply use a capacitor in series with the signal?
This should block DC, but will transfer AC signals.

Then just let this charge a capacitor, which does have a resistor over it to eventually discharge it when it doesn't get charged.

So just something like a small transistor (or FET) to charge the capacitor upto 3V3 via some resistor and a larger resistor value over this capacitor to discharge it
With a ratio of 1:10 you will still get over the logic '1' level of the ESP.
And the series capacitor on the input will filter out any DC signal.

Re: Detect presence of square wave

Posted: 26 May 2023, 02:33
by mackowiakp
THX. Will try.