Simplest way to get square wave from sine?

Discussion in 'General Electronics Chat' started by MangoMan, Apr 29, 2010.

  1. MangoMan

    Thread Starter New Member

    Mar 31, 2009
    6
    0
    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!
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Do you need a 5-0 V or a 5 - (-5) V square wave?
     
  3. MangoMan

    Thread Starter New Member

    Mar 31, 2009
    6
    0
    Zero to 5v will do the trick....
     
  4. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    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.
     
  5. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    Hi Mangoman,

    You can use a NPN transistor to do the job.

    [​IMG]
     
  6. MangoMan

    Thread Starter New Member

    Mar 31, 2009
    6
    0
    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.
     
  7. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    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.

    [​IMG]

    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.
     
    Last edited: Apr 29, 2010
  8. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    A comparator also does this, it will be closer to real than not. Most comparators require a pull up resistor.

    [​IMG]

    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
     
  9. MangoMan

    Thread Starter New Member

    Mar 31, 2009
    6
    0
    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


     
  10. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    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. :)
     
  11. MangoMan

    Thread Starter New Member

    Mar 31, 2009
    6
    0
    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!


     
  12. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    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.

    [​IMG]
     
    kingdano likes this.
  13. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    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.
     
Loading...