Shop OBEX P1 Docs P2 Docs Learn Events
Sine to Square — Parallax Forums

Sine to Square

ArchiverArchiver Posts: 46,084
edited 2003-07-22 20:34 in General Discussion
Whats the easiest waht to convert a low frequency sine (10-100hz) to a square
wave? Opamps or a comparator?


[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-07-22 14:20
    Well, technically a comparator is just a specialized op amp. The classic
    way to do this conversion is to use a comparator (or an op amp) as a
    zero crossing detector.

    The idea is this. No matter what the characteristics of the sine wave
    (frequency, amplitude), it will cross the zero point F times per second
    (where F is the frequency in Hz). So if you take a comparator (or an op
    amp with no feedback) and feed the signal into one input and ground the
    other input, you will get a square wave out.

    Real world problems:

    1) The opamp either needs a negative supply, or you need to shift the
    sine wave so it's zero point is in the middle of the supply range (and
    then that becomes your ground).

    2) The Ft of the op amp/comparator will determine the maximum frequency
    you can handle.

    3) You'll usually want to use a comparator since their outputs are
    usually open collector transistor outputs and they are faster (work at
    higher frequency and produce sharper square edges). That means you'd use
    a pull up resistor to 5V on the output and the comparator will only
    output a ground or float open.

    See http://www.wd5gnr.com/opampneg.htm for some ideas.

    Some links pulled off google:
    http://www.ringolake.com/pic_proj/zcd/zcdmodem.html - Uses MAX232 to
    provide +/- supply

    http://wug.physics.uiuc.edu/courses/Phys344/344exp/Lab1Analog_Digital/la
    b1.htm#Part_4_OpAmp_to_TTL_Interface_Zero_Cross

    http://www.play-hookey.com/analog/comparators.html -- good but not the
    way I'd do it.

    Do a search for zero crossing detector op amp (or opamp) for more. Just
    zero crossing detector will get you a lot of things you don't want.

    Hope that helps.

    Al Williams
    AWC
    * Floating point math for the Stamp, PIC, SX, or any microcontroller
    http://www.al-williams.com/awce/pak1.htm


    >
    Original Message
    > From: Tim Stockman [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=ZWB5eSOU7Kscu1Ebw7z99j5tKYQ9PXtMTK8wBW1-RBS4mbEXAFbyfAbm3dFE5y-YH7qGc1_-P3nRHEV2UMMLy0iPC7JzGTTaZ6Txw9VutA]tim.stockman@s...[/url
    > Sent: Tuesday, July 22, 2003 7:59 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Sine to Square
    >
    >
    > Whats the easiest waht to convert a low frequency sine
    > (10-100hz) to a square wave? Opamps or a comparator?
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-07-22 19:19
    Hi Tim:
    I would use a comparator......you don't need any extra parts as you need
    with an op amp. The LM339 is a good choice. On the other hand, if you have
    an opamp and some resistors in your junk box, and YOU DON'T HAVE the
    comparator, go with the op amp. Kindest regards, Chuck Irwin

    Original Message
    From: "Tim Stockman" <tim.stockman@s...>
    To: <basicstamps@yahoogroups.com>
    Sent: Tuesday, July 22, 2003 8:59 AM
    Subject: [noparse][[/noparse]basicstamps] Sine to Square


    > Whats the easiest waht to convert a low frequency sine (10-100hz) to a
    square wave? Opamps or a comparator?
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-07-22 20:34
    While the comparator or op amp are simple enough, a transistor set up
    as a switch might be good enough, with a switching threshold of 0.6
    volt. Or a logic gate--Schmitt trigger for fast rise times.



    >Whats the easiest waht to convert a low frequency sine (10-100hz) to
    >a square wave? Opamps or a comparator?
Sign In or Register to comment.