Detect presence of square wave

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
mackowiakp
Normal user
Posts: 534
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Detect presence of square wave

#1 Post by mackowiakp » 25 May 2023, 16:40

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?

TD-er
Core team member
Posts: 9153
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Detect presence of square wave

#2 Post by TD-er » 25 May 2023, 17:18

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.

mackowiakp
Normal user
Posts: 534
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Detect presence of square wave

#3 Post by mackowiakp » 25 May 2023, 17:35

Or to use a capacitor connected to GPIO and GND. If ESP32/8266 has Schottky like characteristc.
Does it?

TD-er
Core team member
Posts: 9153
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Detect presence of square wave

#4 Post by TD-er » 25 May 2023, 21:17

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?

mackowiakp
Normal user
Posts: 534
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Detect presence of square wave

#5 Post by mackowiakp » 26 May 2023, 00:26

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.

TD-er
Core team member
Posts: 9153
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Detect presence of square wave

#6 Post by TD-er » 26 May 2023, 01:22

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.

mackowiakp
Normal user
Posts: 534
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Detect presence of square wave

#7 Post by mackowiakp » 26 May 2023, 02:33

THX. Will try.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests