Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Sine to square wave conversion

bob4bvm

Member
I know this must've been covered before but not finding it
Need to convert ~ 4Vp-p sine to 3-5Vpk square wave , low freq, maybe 5kHz max, usually under 1kHz.

This is for a two encoders application, each with Ch A & B, so four channels

Was thinking of a schmidt trigger IC or maybe comparator IC. Trying for a min. parts count ckt ... so maybe a 4093 where i can squeeze all 4 channels thru one IC pkg ?

Thanks
Bob
 
I think you might need two steps for this one.
  1. Add a +2V offset to the sine wave.
  2. Use a Schmitt Trigger to convert the sine wave to a square wave.
 
1. Does the resulting square wave have to have a 50% duty cycle?

2. What voltages are available to power the conversion circuit?

3. Is the input sine wave centered about GND?

4. Is the input sine wave coming from a low impedance source?

ak
 
This is using SPICE which is not real world.
I used a simple inverter. 5V supply. CMOS. Set to switch at 1/2 supply. Parts will switch from L to H where they want, not at exactly 1/2 supply. I tested at 2.0V 2.5V and 3V and the duty cycle changes accordingly. The 4093 will also work. If you need exactly 50% then we need a different family of parts.
1680394689026.png
 
For position encoders, it needs to work down to DC, and symmetry is important to keep good edge separation of the output quadrature signals.

If they have balanced outputs, as many encoder do, I'd suggest a line receiver such as an AM26LS52.
Most modern sinewave encoders give a 1V signal and are intended to work with a 100 Ohm terminated input.

Connect both signals from a channel (eg. A & /A) to the receiver inputs and add a 100 or 120 Ohm resistor across the connections.

The 26LS32 has four receivers, so you could either use them for A & B signals on two encoders, or A-B-Z on one encoder and duplicate it with a second IC for the other encoder.


If they are single-ended outputs, just one connection for each signal, you can use the same ICs but connect the receiver second input to either a voltage divider to give about the mid level of the signal voltage, or a preset pot, eg. 1K, connected across the 5V supply.

That would allow you to adjust the bias level to get the best symmetry from the square wave output.

Add a capacitor from the divider output or preset wiper to 0V. One such circuit should provide a bias for all the receivers.

If you cannot get the 26LS32, you could substitute an LM339 with pullup resistors added to its outputs, or an LM311 for each encoder channel, with a pullup.
 
Here's the simulation of Ron's basic circuit in post #4 with a CD4093 model:

Note the interesting thing about this circuit is that, after the initial transient (not shown), the output has a 50% duty-cycle independent of the input amplitude.
That's because the only stable condition with the capacitor coupling is where the average current through R1 is zero.
That occurs when the input level at node "a" is where the average DC output is 1/2 Vdd or 50% duty-cycle.
If the output is not 50% then the average current through R1 is not zero, causing the node "a" DC bias to change until 50% is reached.
This is also independent of the CD4093 input transition voltage.
Basically it has negative feedback adjusting the bias point to cause a 50% duty-cycle output.

1680458751722.png
 
Last edited:
That's because the only stable condition with the capacitor coupling is where the average current through R1 is zero.
But...

It has to work down to DC. It's a position measuring system, it cannot be capacitor coupled.

Edit:
See page 18 of this, for typical sine wave encoder signals and interfacing, though the example is a receiver that retains the sine waveform rather than converting to logic:
 
Last edited:
Those two schematics shown above (posts #4 and #6) are not reliable.

The first (#4) is a high-gain amplifier, that will amplify any noise on the input if used with non-schmitt-trigger inverter, and will oscillate if used with schmitt-trigger inverter (when the input signal frequency becomes low). The second (#6) will oscillate when input frequency is low.

If this is for displaying the encoder count, as mentioned in the link in #10, then the best solution would be to use a microcontroller. The shifted quadrature signal could be read directly by four ADC channels.
 
Those two schematics shown above (posts #4 and #6) are not reliable.

The first (#4) is a high-gain amplifier, that will amplify any noise on the input if used with non-schmitt-trigger inverter, and will oscillate if used with schmitt-trigger inverter (when the input signal frequency becomes low). The second (#6) will oscillate when input frequency is low.

If this is for displaying the encoder count, as mentioned in the link in #10, then the best solution would be to use a microcontroller. The shifted quadrature signal could be read directly by four ADC channels.
You are wrong about post #4. That is not a high gain amplifier. It is an inverter with properties that may be specified but not shown on the schematic. It is one of the special devices in LTspice. You would know this if you were familiar with that piece of software. There was never a claim for this circuit that it was realizable in practice.

As for the operation at low frequency, a lower limit was never mentioned as a requirement in the original post by the TS. The TS might want to amend his query if there is such a requirement.
 
Last edited:
Because bob4bvm has not come back/responded to "DC" questions, I am going to stop guessing on what is needed.

I lied, one more try. Because I was not clear that "~ 4Vp-p sine" is, I tried to make a circuit that finds the center of the waveform. If the circuit really needs to go to DC, then we need a reference voltage that indicates where zero is. Then the answer is clear.
----------------
Compare circuit #4 & #6. The difference is R2. I would choose 1k or something to limit the inrush current. I was relying on the input perfection diodes to help box-in the ac coupled signal. (SPICE might not have the diodes, did not check) With a (low value of R2 and protection diodes) the signal should very quickly move so it is boxed-in by -0.7 to +5.7V. Then at a slower rate the RC time constant moves the center of the waveform to 1/2 supply.
1680479080883.png

Now I will try to not make more comments until I know more.
 
I lied, one more try. Because I was not clear that "~ 4Vp-p sine" is, I tried to make a circuit that finds the center of the waveform. If the circuit really needs to go to DC, then we need a reference voltage that indicates where zero is. Then the answer is clear.
----------------
Compare circuit #4 & #6. The difference is R2. I would choose 1k or something to limit the inrush current. I was relying on the input perfection diodes to help box-in the ac coupled signal. (SPICE might not have the diodes, did not check) With a (low value of R2 and protection diodes) the signal should very quickly move so it is boxed-in by -0.7 to +5.7V. Then at a slower rate the RC time constant moves the center of the waveform to 1/2 supply.
View attachment 141058
Now I will try to not make more comments until I know more.
Now set the input frequency to <50Hz. You have formed a schmitt-trigger oscillator.
iu
 
There is obviously a low frequency limit to the capacitive coupled circuits.
Until we know what that is, we are only speculating.
 
Thanks for the help guys !
I had fine success using Crutschow's ckt
For some reason, using the input cap, i got a nice triangle wave output.
Deleting the cap gave me a decent square useable for my purposes.

Sorry i did not give enough detail.

This is pretty non-critical. The encoders are sine output, so i just wanted to square up the edges a bit to give the uC a nice edge to count. This ckt makes the count alot more reliable at the low frequencies i am using.
The project is for telescope position sensing, so nothing is moving all that fast.
Cheers
Bob

Here is the result:

Encdr sine-to-square schmitt ckt.jpg
 
Thanks for the help guys !
I had fine success using Crutschow's ckt
For some reason, using the input cap, i got a nice triangle wave output.
Deleting the cap gave me a decent square useable for my purposes.

Sorry i did not give enough detail.

This is pretty non-critical. The encoders are sine output, so i just wanted to square up the edges a bit to give the uC a nice edge to count. This ckt makes the count alot more reliable at the low frequencies i am using.
The project is for telescope position sensing, so nothing is moving all that fast.
Cheers
Bob

Here is the result:

View attachment 141062
What uC are you using?, many (most?) modern PIC's have optional Schmitt trigger inputs - so by setting those to Schmitt you can avoid the external Schmitt.
 
Considerations for sine/cosine to pulse conversions :



The CD4093 has strongly dependent trip levels in its inputs, with wide variation, so
you get garbage in garbage out results over T & V and component tolerance. CMOS
gate solutions are to timing solutions as shovels are to open heart surgery, usable
but not really a good idea or repeatable or reliable :) And then we have the electrolytic
caps used to get long delays and their wonderful initial out of the box accuracy and
environmentals.. All result in duty cycle wide variation.

Whereas using a comparator with an onboard Vref (they are available), or a sampled data
approach using processor and A/D can produce much better results.


Regards, Dana.
 
Last edited:
Last edited:

Latest threads

New Articles From Microcontroller Tips

Back
Top