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.

Once again...Sine Wave To Square with Comparator

Status
Not open for further replies.

mrrmot

New Member
Need Help! Sine Wave To Square with Comparator

Hey everyone! :D

I am doing a project with a pic microcontroller.

Now I just need to convert the input sine signals (frequency: 50/60 Hz) to really really good squares. When the sine signal is positive the output has to be 5V, when the sine signal is negative the output has to be 0V. I want to use a comparator (maybe lm393, lm339, lm311) but I can't figure out how to connect a comparator for my purpose. The datasheets are no help. If someone has a scheme, I'd really appreciate it, or any other help!​

Thanks a lot, guys! :eek:
 
Last edited:
mrrmot said:
Hey everyone! :D

I am doing a project with a pic microcontroller.

Now I just need to convert the input sine signals (frequency: 50/60 Hz) to really really good squares. When the sine signal is positive the output has to be 5V, when the sine signal is negative the output has to be 0V. I want to use a comparator (maybe lm393, lm339, lm311) but I can't figure out how to connect a comparator for my purpose. The datasheets are no help. If someone has a scheme, I'd really appreciate it, or any other help!​

Thanks a lot, guys! :eek:
hi,
Where are going to connect your 50/60Hz source in order to drive the comparator input.?
 
If you're asking about where to connect the sine signals, well that's exactly my problem. I don't know it.

I have those 2 sine signals and want to use a comparator, but don't know how to do the connection. Btw: I have a 5V and 12V DC voltage source in my system
 
mrrmot said:
If you're asking about where to connect the sine signals, well that's exactly my problem. I don't know it.
No thats not it.

I have those 2 sine signals and want to use a comparator, but don't know how to do the connection. Btw: I have a 5V and 12V DC voltage source in my system

hi,
Its the 2 sine wave signals, ie: source and amplitude I am asking.

EDIT:
When a posting says 50/60Hz its possible its a mains application.
Is the source the local mains supply, if YES, how are you planning to reduce it to a safe level before its input to the comparator.?
If NO, is the signal in millivolts or volts..?

Its not possible to suggest a comparator circuit until we know this detail.
 
Last edited:
Those 2 sine signals are generated by a voltage generator. My project is supposed to work with sine singnals of any given amplitude that's smaller than 220V.
 
mrrmot said:
Those 2 sine signals are generated by a voltage generator. My project is supposed to work with sine singnals of any given amplitude that's smaller than 220V.

When a posting says 50/60Hz its possible its a mains application.
Is the source the local mains supply, if YES, how are you planning to reduce it to a safe level before its input to the comparator.?

hi,
How are you planning to reduce the 220Vac to a safe level before its input to the comparator.?
Can you give more details of the project, whats it going to do.?
 
The sine signals need to be converted to (as ideal as possible) squares. The square signals are the inputs of a XOR IC. The output of that XOR IC is connected to the pic microcontroller, which is supposed to measur the phase shift angle of the original sine signals. I've already figured out the algorithm and the software. I just need those squares now.
 
mrrmot said:
The sine signals need to be converted to (as ideal as possible) squares. The square signals are the inputs of a XOR IC. The output of that XOR IC is connected to the pic microcontroller, which is supposed to measur the phase shift angle of the original sine signals. I've already figured out the algorithm and the software. I just need those squares now.

hi mrrmot,
I am trying to help, but you are not answering my questions.

How are you planning to reduce the 220Vac to a safe level before its input to the comparator.?

Do you have a mains step down transformer from 220Vac down to, say 6 or 12Vac.?

The processing of the square wave output has been solved by you OK.
 
I am very thankful for your help. Sorry, I forgot to answer yor question. Yes, I'll be using a transformator, but my teacher hasn't told me to what voltage yet. I guess it'll be 220Vac-5Vac or 220Vac-12Vac. So how to do the comparator part?
 
mrrmot said:
I am very thankful for your help. Sorry, I forgot to answer yor question. Yes, I'll be using a transformator, but my teacher hasn't told me to what voltage yet. I guess it'll be 220Vac-5Vac or 220Vac-12Vac. So how to do the comparator part?

No problem,

I'll draw up a LM393 comparator circuit and post it.
If you are using TTL or LS, a +5v output from the comparator would be compatable, this 5V level would also make it suitable for the PIC.

Its late evening in the UK, so I'll post tomorrow.
 
I know that it is evening, I'm from Europe as well :) Thanks a lot for the help, I really appreciate it. Btw: Do you know where I can simulate the comparator circuit? I usually work with Proteus, but it doesn't have the LM393 simulation model

Thanks for everything
 
Hi Mrrmot,

Here is something you can work with, it was only a simulation
but it's close to the real thing.

**broken link removed**

on1aag.
 

Attachments

  • Zero crossing circuit.PNG
    Zero crossing circuit.PNG
    19.9 KB · Views: 931
  • Waveforms.PNG
    Waveforms.PNG
    17.4 KB · Views: 580
Now I just need to convert the input sine signals (frequency: 50/60 Hz) to really really good squares. When the sine signal is positive the output has to be 5V, when the sine signal is negative the output has to be 0V. I want to use a comparator (maybe lm393, lm339, lm311) but I can't figure out how to connect a comparator for my purpose. The datasheets are no help.
Hi,
Checking thru the LM393 datasheet, there is an application circuit that meets your requirement.
See attached extract from the LM393 datasheet.

Its a zero crossing detector, feed the 6Vac from the mains isolating transformer into the Vin input
and connect the XOR gate input to the LM393 output.
Use a single +5V supply for the LM393 and XOR logic.

If you cannot simulate a LM393, try any single supply comparator that you have in the sim,,, or even a good quality OPA.

Lets know how the sim goes.:)
 
Last edited:
Hey ericgibbs,

I've done the simulation with op-s, and everything works fine. I wanted to use a comparator because I thought they are more precise.

Thanks a lot for the above circuit. One more question: Which is the max voltage that I can connect to the Vin input of LM393 in the above circuit? Do I have to change anything in the scheme if the amplitude of the sines is 5V, 12V or 15V?

Thanks for everything
 
mrrmot said:
Hey ericgibbs,

I've done the simulation with op-s, and everything works fine. I wanted to use a comparator because I thought they are more precise.
They are designed as comparators not OPA's so you are correct.:)

Thanks a lot for the above circuit. One more question: Which is the max voltage that I can connect to the Vin input of LM393 in the above circuit? Do I have to change anything in the scheme if the amplitude of the sines is 5V, 12V or 15V?
Thanks for everything

hi,
The diode clamps that range of negative input voltage half cycles, it has a 5K1 resistor in series with the diode so the current is also limited to a safe level.
If you are concerned about the higher positive half cycles, you could replace the diode with say a 3.9V zener.

Do you follow that.?

EDIT: added dwg
 
Last edited:
Yeah, thanks, I think this should work well, now I can finish my scheme. I'll let you know whether my teacher approved it.

Thanks
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top