# Sine to sqare waveform but with variable peak-to-peak input

I need to calculate the speed of a little generator that produces a bipolar sinusoidal waveform with a peak to peak voltage value variable with the velocity. The produced signal also has a frequency proportional to the velocity. I prefer to process the frequency than the voltage, because I have a direct relation between revolution and speed. Four produce periods are corrispondent to one revolution of the generator drive shaft. My requirements are:

• Max RMS output generated voltage = 45 volt, at the maximum velocity.
• Max output generated frequency=50 kHz at the maximum velocity.
• A square signal circuit output to be sent to the micro min = 0 V, max = 5 V.
• Only unipolar voltage to 12 V or 5 V to supply the circuit.

So I thought to a Schmitt trigger op-amp comparator like this.

But I have two problems:

• Due to the variable peak to peak signal I cannot fix the two comparator's threshold VH, VL.
• I have to scale (I think) the voltage produced by the generator to avoid to damage the op-amp. Here could be sufficient a voltage divider to the non inverting pin, fixing the divider resistors to have a value that at the maximum RMS signal 40 V, produce for example Vcc.

Any idea how I could proceed?

update:I attached a wrong figure (a comparator), instead I would attach a schmitt trigger because from what I read, the only comparator (without positive feedback) could create false trigger in the output due to a noisy input.

Thanks a lot.

• What is the smallest RMS voltage produced that you need to support at the minimum velocity?
– jonk
Commented Mar 30, 2019 at 19:42
• 80-100 mV that corresponds to more o less 1 revolution per second. I would evitate to measure the speed by a voltage (by the internal micro AD) to be independent to the specific alternator relation efm-revolutions that would need to be adjusted by a potentiometer during the tuning phase of the circuit. I would only set the number of poles as parameter in the code. Commented Mar 31, 2019 at 15:03
• You can do this with just a few bjts and no vref, as well. But I don't want to discourage your use of a comparator.
– jonk
Commented Mar 31, 2019 at 15:16

## 1 Answer

First, use a comparator rather than an op-amp. They're designed for your application and don't latch up when the input gets close to the rail voltages.

Max RMS output generated voltage = 45 volt, at the maximum velocity.

A resistor divider will do the job. Add a diode between ground and the input (pointing up in your diagram) to prevent the voltage going negative. Make the VREF close to ground so you can detect low-amplitude signals accurately.

Max output generated frequency=50 kHz at the maximum velocity.

Shouldn't be a problem.

A square signal circuit output to be sent to the micro min = 0 V, max = 5 V.

Most comparators have an open-collector output so a pull-up resistor to the 5 V supply will give you the required square-wave signal.

Only unipolar voltage to 12 V or 5 V to supply the circuit. So I thought to a Schmitt trigger op-amp comparator like this.

So far, so good - but use a proper comparator.

Due to the variable peak to peak signal I cannot fix the two comparator's threshold VH, VL.

You only need one comparator. Since the voltage is alternating you can set the threshold very close to 0 V.

I have to scale (I think) the voltage produced by the generator to avoid to damage the op-amp. Here could be sufficient a voltage divider to the non inverting pin, fixing the divider resistors to have a value that at the maximum RMS signal 40 V, produce for example Vcc.

You've got it. Don't forget that peak will be $$\ 40\sqrt 2 \$$.

• Thanks transistor! I updated the question. Using only one trigger point (as comparator do) could be a good idea but don't you think that the comparator (and not the schmitt trigger) could produce false trigger due to noisy input? Thanks. Commented Mar 31, 2019 at 22:30
• Yes you are correct, I would draw a schematic to show how to connect a comparator so it rejects noise, but for some reason I can't access editor. You will have to wait until someone else comes along. Commented Apr 1, 2019 at 2:51