Simplest way to get square wave from sine?

Thread Starter

MangoMan

Joined Mar 31, 2009
6
Hi guys. I have a 12v AVC sine wave (i.e. -12v to +12v) from which I would like to get a square wave. I just want the frequency so I don't care about the negative side of it. My circuit itself is 5v. What is the simplest way to generate a nice square wave from this? Thanks!
 

mik3

Joined Feb 4, 2008
4,843
Use a zero cross detector circuit with an op amp. This will output a +Vout and a -Vout. Then use a diode to remove the -Vout and get a signal between zero and +Vout.

There are other ways to do it but this is a simple one.
 

Thread Starter

MangoMan

Joined Mar 31, 2009
6
Hi Chung. Yes that seems to work, but the square wave is not that "square" and I wonder if a micro would have a problem reading it (in an interrupt mode).

I have attached another circuit, which seems also OK, but for some reason pulses do not start from zero. Any idea why not? Thanks.
 

Attachments

eblc1388

Joined Nov 28, 2008
1,542
Hi Chung. Yes that seems to work, but the square wave is not that "square" and I wonder if a micro would have a problem reading it (in an interrupt mode).
Good concern regarding interrupt. One can do better with the edge by adding another NPN to form a Schmitt Trigger. This time the edge is fast.



I have attached another circuit, which seems also OK, but for some reason pulses do not start from zero. Any idea why not? Thanks.
I think it has to do with the IC Opamp you have used. Can it output 0V level?

By the way, it seems the frequency output from your circuit is double of that of the AC input?

P.S. Just notice in your simulation, 10m is 10 milliohm, in LTSPice, 1000K is written as 1MEG.
 

Attachments

Last edited:

Wendy

Joined Mar 24, 2008
23,421
A comparator also does this, it will be closer to real than not. Most comparators require a pull up resistor.



A Schmitt Trigger will also do a good job of this, though you may have to also bias it similar to the comparator.

555 Schmitt Trigger
 

Attachments

Thread Starter

MangoMan

Joined Mar 31, 2009
6
Hey thanks for the clarification on the resistor values in LTSpice!
Now I have another question, in your schematic, what is the function of D1? I disconnected it in the simulation and seems there is no effect.

Thanks


Good concern regarding interrupt. One can do better with the edge by adding another NPN to form a Schmitt Trigger. This time the edge is fast.





I think it has to do with the IC Opamp you have used. Can it output 0V level?

By the way, it seems the frequency output from your circuit is double of that of the AC input?

P.S. Just notice in your simulation, 10m is 10 milliohm, in LTSPice, 1000K is written as 1MEG.
 

eblc1388

Joined Nov 28, 2008
1,542
Now I have another question, in your schematic, what is the function of D1? I disconnected it in the simulation and seems there is no effect.
The diode is there to protect the transistor from the negative cycle of the AC input.

Given enough reverse voltage(6~9V) on the transistor base, its base-emitter junction will breakdown.

Of course this will not happen in simulation. :)
 

Thread Starter

MangoMan

Joined Mar 31, 2009
6
OK, understood.
So now for the grand finale..... :D
If the input for this is from one phase of an automotive alternator where there may be spikes and transients, what type of input protection would you add? (and is there a need to add a cap to block any DC elements?).
And secondly, if the output is to a 3.3v TTL logic microcontroller, any changes? (apart from the Vcc being 3.3v and not 5v.....)
Thanks!


The diode is there to protect the transistor from the negative cycle of the AC input.

Given enough reverse voltage(6~9V) on the transistor base, its base-emitter junction will breakdown.

Of course this will not happen in simulation. :)
 

eblc1388

Joined Nov 28, 2008
1,542
If the input for this is from one phase of an automotive alternator where there may be spikes and transients, what type of input protection would you add? (and is there a need to add a cap to block any DC elements?).
And secondly, if the output is to a 3.3v TTL logic microcontroller, any changes? (apart from the Vcc being 3.3v and not 5v.....)
Thanks!
For that you'll need to add an input filter to prevent the transients from affecting your circuit.

In the simulation I have replaced the input with a voltage that has transients on it and you can see the effect of the LC filter on cleaning the input waveform. After the LC filter, the waveform is in pretty good shape. The transistor works OK with 3.3V supply.

You have to experiment a bit with the value of L & C to get one that work best.

 

Attachments

SgtWookie

Joined Jul 17, 2007
22,230
10 millihenries is quite a large value for a choke.

Funny, I don't know offhand what the freq range would be from an alternator - but they might spin at up to 3x the engine RPM (depending on the drive pulley to alt pulley ratio) and the number of poles in the stator / 3.

Be aware that temps at the alternator's bridge rectifier will be amongst the hottest under the hood (besides the exhaust system).

If you try to connect to the bridge using ordinary "automotive wire", it's very likely the poly insulation will melt right off, and you will wind up having a shorted phase in the alternator. This will be a very unpleasant situation, as the regulator will send maximum current through the field to bring the voltage up, rapidly burning up your wire. You may wind up with a fire.
 
Top