# Frequency detector/comparator problem

I have recently learned about schmitt and comparator op amps, and I came up with an idea to build a "frequency comparator" (if it is called like this). The function of this circuit is to maintain an output high or low depending on the frequency of the signal at the input, compared with a preset trigger frequency. What I wanted to accomplish with this circuit was and is a frequency detector independent of the amplitude of the signal at the input.

simulate this circuit – Schematic created using CircuitLab

How I wanted to accomplish this was to first build a non inverting comparator at the input, with a low trigger voltage (something around +/- 0.1V). This way a square wave would be created at the output with a constant amplitude and a frequency dependent on the signal seen at the input only (the comparator triggers only if we assume that all input signals are above 0.1). The output wave would then be taken into a following stage, composed of a lowpass filter at the input and a second non inverting comparator. the trigger voltage is set at approximately -/+ 3.535V, the voltage equal with 0.707*5, when the lowpass filter reaches its cutoff frequency. Any frequency above the cutoff will be of a smaller amplitude than the threshold, resulting in the output being low. And in reverse, any frequency at the input smaller than the cutoff will result in the output being triggered to high. The output will then be probably taken in a next stage where it is rectified and ready to activate a component (be it transistor, LED, relay, piezo driver, motor or whatever). The cutoff frequency can be, of course, controlled with a pot, multiplexer etc. Here I chose a cutoff at approximately 1500H.

My problem is that this circuit misbehaves. Testing the circuit with only the first part works great. The second part misbehaves beyond my undestanding. Putting the circuit together in one piece, the second stage interferes is such a way to create chaos (at times). At low frequencies, the output stays at ground, at frequencies slightly above 1500, the output also stays at ground. And, at higher frequencies, the output stays high. In the middle of low and high, the output oscillates. What is going on? I am not very comfortable with non inverting comparators, but I like their simple and symmetrical threshold and their properties. Is there created a high pass filter somewhere ehich unables small frequencies to trigger the output? Any suggestion is welcomed. Help, please!

simulate this circuit

[![testing the first stage alone works great][1]][1]

Testing the first stage alone works great

• The output of stage two (OA2) won't necessarily be low when its input drops below a certain amplitude, and high otherwise. It's a schmitt trigger whose ouptut will be a square wave of the same frequency as the input, as long as the input signal swings beyond its thresholds. When input amplitude drops enough that it no longer reaches those thresholds, it will simply remain at its last "triggered" value, which could be either high or low. Nov 8, 2023 at 14:33
• I noticed that. I just modified the schematics and replaced it with a comparator with 0 hysteresis. Nov 8, 2023 at 14:51
• Another issue (assuming the purpose of the first stage was to create a square wave) is that a low-pass filtered square wave's amplitude (peak-to-peak swing) does not decrease with frequency in the same way a sinusoid would, due to the all the harmonics present. I estimate that a square wave's frequency would have to be nearly twice the filter's cut-off frequency, in order to produce a signal with peak-to-peak swing of 0.707× original amplitude. Nov 8, 2023 at 15:00
• I didn't know this. Thanks. I had to modify the resistor value till my hand collapsed, because the amplitude simply refused to obey the cutoff frequency. Nov 8, 2023 at 15:04
• Removing hysteresis won't fix anything. You need a lot of hysteresis to detect whether amplitude is sufficient, but as it stands all you have is something that oscillates when amplitude is big enough, and gets stuck "randomly" high or low otherwise. Nov 8, 2023 at 15:04

NOTE: In your 2nd and 3rd schematics, components with the same reference designators have different values and do different functions. This is very confusing. Please update your post so the reference designators are consistent across all three schematics. In my answer, the refdes are all from the first schematic.

Another term for this type of circuit is a missing pulse detector. What is missing from your circuit is an FM detector. Add one diode.

If you replace R4 with a diode, and put a resistor across C1 (call it R7), the waveform going into the second stage will now be an elevated sawtooth. The positive edge of the squarewave coming out of OA1 will charge up C1 rapidly. When the OA1 output goes low, the diode reverse-biases, disconnecting the OA1 output from the rest of the circuit. C1 will discharge into the parallel resistor until the next positive output from OA1. The resulting voltage into OA2 is a DC level representing the frequency of the input, plus some ripple at the input frequency.

The greater the frequency difference between the input freq and the R7-C1 corner frequency, the less the ripple. Low ripple is good, because it prevents "chatter" (the output changing state with each input cycle) at the output of OA2 when the input frequency is very near the trip value. The tradeoff is that the detector will be slower to respond. If there is s step-change in input frequency above-below the trip value, it may be many cycles before the circuit output changes state.

A simplified form of this is a very common circuit for detecting fan failure based on a tach signal.

Why do you have such a large amount of hysteresis in the OA2 stage?

Also - In your circuit, R4-C1 form a 1.3 kHz lowpass filter. Other than rounding off some of the corners of the squarewave out of OA1, what is it supposed to do?

UPDATE: Forgot one resistor. Leave R3 in place. This limits the charging current into C2. Now C2 is charged up by the input signal through R3 at a rate that varies with frequency, and discharged through R7 at a constant rate. This imbalance creates a voltage across C2 that varies with frequency.

• Regarding your last comment on hysteresis: a mistake. I actually wanted to build a comparator with 0 hysteresis, given that the output from O1 has no noise. I wasn't paying attention when I built the circuit and it caused a part of my confusion. I have repaired it afterwards. I didn't know a circuit similar to this one exists. I intentionally built the R4-C1 low pass filter as a way to measure the frequency at the output. As you mentioned, it has a cutoff frequency equal with 1.3k, not 1.5k, the motive being, as you mentioned, because I encountered some ripple. Nov 8, 2023 at 14:28
• ...So I trimmed the resistor a bit to get rid of the ripple. Returning to the lowpass filter: what I hoped, was to place the threshold value of O2 at 3,535V, approximately. By setting the pot resistor R4, I was hoping to "control" the cutoff frequency at which the amplitude would fall to 0.707 of the initial amplitude, so to trigger the O2 comparator. It works pretty well, once I did the modifications. Nov 8, 2023 at 14:36
• I will adapt the schematics Nov 8, 2023 at 14:37
• The idea is a rite-of-passage for circuit designers. Like you, I developed it (in the mid-70's) independently of what was out in industry. Then I saw it in trade magazines, then I saw it in the applications section of fan catalogs. Nov 8, 2023 at 14:38
• I see that now. I haven't designed many circuts so far, so I wanted this one to be one of my firsts. I am considering to solder it on a DIP PCB once I revise the schematics, build a rectifier and so on. I am only concerened about soldering my fingers... . I am curious if it works as a filter in combination with some other components, I am only afraid about the circuit's speed in real circuitry. Nov 8, 2023 at 14:58

There are a variety of frequency-to-voltage and voltage-to-frequency ICs, if you want to go down that route.

Another option, if you want to make such a system, would be to use the output of a non-retriggerable one-shot to generate a constant-width pulse on positive-going zero crossings (triggered by the output of a simple comparator). The pulse width should be fairly narrow, to accommodate high-frequency use.

Then, take the output of the one-shot, and low-pass-filter the hell out of it, to turn it into a rolling averager. The faster your frequency, the larger the analog output of the low-pass filter.

• This idea sounds cool. I was also considering using a constant width pulse at the output of the circuit above, so that the output high (here being represented by continuous oscillation) to create one, single, lengthy pulse (or narrow, depending on the project). I noticed something pretty cool, that by using a non inverting schmitt trigger with a capacitor in series with the feedback resistor you can create a constant width pulse at the output and I considered implementing the idea. I am curious, would in theory a frequency detector work by using an uncompensated op amp for achieving phase... Nov 8, 2023 at 15:40
• Shifts, intentionally? At high frequencies the phase shift could reach 180* and transform negative feedback in positive one, perhaps acting as a trigger. I am curious if it works better and with fewer components being used than the circuit above. Nov 8, 2023 at 15:43
• That is a pulse-integrating FM detector, used in the Heathkit digital FM stereo receiver and the core of broadcast video recorders in the 60's and 70's. Ampex had a 2-tube (and later, 2-transistor) pulse circuit. RCA couldn't copy that, so they had a multi-foot coil of unterminated thin coax that they banged on, then used the reflection to terminate the pulse. Clunky, but surprisingly stable. Nov 8, 2023 at 16:25
• "low-pass-filter the hell out of it" - this has the same tradeoffs as the variable pulse widths you get out of a simple squaring input stage - the more heavy the filtering, the more precise the frequency detection is; but with longer the time lags in both in-band and out-of-band transitions. Nov 8, 2023 at 16:29
• "low-pass-filter the hell out of it" - this has the same tradeoffs as the variable pulse widths you get out of a simple squaring input stage - the more heavy the filtering, the more precise the frequency detection is; but with longer the time lags in both in-band and out-of-band transitions. Since this is a single trip-point detector, not an audio or video system, a linear relationship between frequency and voltage is not required. Nov 8, 2023 at 16:34