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

Status
Not open for further replies.

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
 
Need to convert ~ 4Vp-p sine to 3-5Vpk square wave , low freq, maybe 5kHz max, usually under 1kHz.
The search term for this is "comparator" These can be AC or DC coupled to trim for asymmetry.
The design parameters would be tolerances for asymmetry , slew rate , frequency and amplitude here is easy, unlike uV..

"De-Noiser, Slicer and amplifier" are also used with Comparator.s.

But we surmise you are not fussy about precision here and more focused on cheap and simple.

edit:
After reading more of the thread, it seems you have some sine position encoder. Is it a Sin/Cos encoder? with direction and cycle counts?


In any case, the leading edge only needs to be noise free to count cycles, and we don't know if phase or low frequency response is important and it seems your sine is DC biased and output uses a 3,.3V supply.


A better question always gives a better answer. ( include all specs, tolerances and purpose. with sensor links)

- it also appears you are DC coupling and put the Cap in Crutshow's (?) cct in shunt rather than in series. or R was way too small < 100 rather than 1M
just guessing... since shunt RC response integrates a square wave into a triangle.
 
Last edited:
Here is a simulation how leading and trail edge shift with CMOS threshold voltage using a slide on the side.

There are differences between the reliable slow CD4xxx inverter gates with unbuffered gains of >10 and triple stage or Buffered gains of >> 1000 and the much faster 74HCxx series and 74ALCxx series for gain and bandwidth.

Ceramic supply caps are essential near the part to prevent amplifying transition noise.


But I fear we are presuming too much already.
1680624351243.png
 
Thx again guys
More info is due i guess...
My encoders are 5V optical quadrature with A, B, Z outputs. Not using Z for cycle cnt, only A&B for posn and dir. of travel.
As stated i am not using the input cap. Deleting it produced the sq wave shown on scope.
I am using an ESP32 to do the counting and output position
Not sure if the inputs are settable to 'schmitt'. I know way less than enough to be dangerous with uC's; got alot of help with this one. Being an old analog/discreet guy with a ton of that kind of chips on the bench, i tend to hardware solutions so i guess that's why i went this route.
For the Schmitt ckt above, i had some 74HC132s here so used that. seems to work fine for my appln as noted above
Also tried my old go-to LM339 CMP which worked equally well for this. would have just used the 339, but had more of the 132's to play with
Bob
 
Last edited:
Thx again guys
More info is due i guess...
My encoders are 5V optical quadrature with A, B, Z outputs. Not using Z for cycle cnt, only A&B for posn and dir. of travel.
As stated i am not using the input cap. Deleting it produced the sq wave shown on scope.
I am using an ESP32 to do the counting and output position
Not sure if the inputs are settable to 'schmitt'. I know way less than enough to be dangerous with uC's; got alot of help with this one. Being an old analog/discreet guy with a ton of that kind of chips on the bench, i tend to hardware solutions so i guess that's why i went this route.
For the Schmitt ckt above, i had some 74HC132s here so used that. seems to work fine for my appln as noted above
Also tried my old go-to LM339 CMP which worked equally well for this. would have just used the 339, but had more of the 132's to play with
Bob

No Schmitt on an ESP32 I'm afraid :(
 
The nice feature about quadrature or sin/cos decoders if done right is that even if there is a bunch of edge noise is as long as the other sensor is stable (0 or 1) no further counting is done after the 1st leading edge change. So denoising is not required as long as only 1 channel is noisy during low levels near the transition threshold. That means even two sinusoids within the acceptable input logic voltage range exceed the drift due to temp. or Vdd will still work.

Of course, increasing the amplitude increases SNR which statistically reduces the error rate.

Trivia question: If analog SNR of 10:1 gives some low error rate say 10^-8, what is the logic error rate of 5V logic with a slew rate of < 1% of the period?
 
Thx again guys
More info is due i guess...
My encoders are 5V optical quadrature with A, B, Z outputs. Not using Z for cycle cnt, only A&B for posn and dir. of travel.
As stated i am not using the input cap. Deleting it produced the sq wave shown on scope.
I am using an ESP32 to do the counting and output position
Not sure if the inputs are settable to 'schmitt'. I know way less than enough to be dangerous with uC's; got alot of help with this one. Being an old analog/discreet guy with a ton of that kind of chips on the bench, i tend to hardware solutions so i guess that's why i went this route.
For the Schmitt ckt above, i had some 74HC132s here so used that. seems to work fine for my appln as noted above
Also tried my old go-to LM339 CMP which worked equally well for this. would have just used the 339, but had more of the 132's to play with
Bob

You could effect a Schmidt on an ESP32 if you have the available pins. Basically config
one for open drain, the other as the input. Put a R divider on input, configured for very small
divide ratio, and add a high valued R from pin to open drain pin. Then using an ISR change the
open drain output from on to off, or vice versa, to alter the trip level of the input. A bit toady
but possible. Will that handle speed needed, not sure.

A sim :

1681058200724.png



Switch is the open drain MOSFET pin. Inversion is ISR code generated inversion
from input pin.

Never tried it, would be easy to check suitability.


Regards, Dana.
 
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
You forgot to quote Vmin, DC offset, fmin (0?), SNR ( if in noisy env.) and Z(ohms), single-ended or differential.
Or use some link to define sensor specs.
 
You forgot to quote Vmin, DC offset, fmin (0?), SNR ( if in noisy env.) and Z(ohms), single-ended or differential.
Or use some link to define sensor specs.
This is up and running. I used the Schmitt ckt above, i had some 74HC132s here so used that. seems to work fine for my appln as noted above.
Later i discovered that my particular encoders read fine into the ESP32 if i simply used a pull-down resistor on each encoder channel. So that is the simplest solution for me.
Thanks to all for the good suggestions !
Bob
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top