(Might be impossible) Square Wave Frequency "Rounder"

Discussion in 'General Electronics Chat' started by jarek319, Aug 27, 2010.

  1. jarek319

    Thread Starter New Member

    Jan 24, 2010
    I have an instrument generating square waves up and down the audio spectrum. I'm wondering if it is even possible (using TTL gates and op-amps) to 'autotune' my square waves.

    For example, if my instrument plays 430Hz < x < 450Hz, where x is the frequency it is playing, this series of gates and opamps would output 440Hz. The next step would be 460 Hz, 480 Hz, etc. These are just general frequencies, I'm not asking for calculations to be done on my behalf.
  2. JDT

    Well-Known Member

    Feb 12, 2009
    Possible, yes.

    The device would have to pick up 1 or 2 cycles of the incoming signal to get a measurement of the frequency before outputting the required frequency. I take it that 440Hz is a clue - middle C. So your output will be one of a list of musical notes?

    Probably the best way to do this is using a small micro-controller. Not straight forward though!
  3. SgtWookie


    Jul 17, 2007
    Trying to use TTL gates and opamps for such a thing would get out of hand very quickly (I'm talking a big pile of parts).

    If your instrument is monophonic (just a single note at a time) then it likely could be done pretty easily with a single uC (microcontroller), like JDT said. If your instrument is polyphonic, (can play more than one note at a time) then the signal processing could get hairy in a big hurry.

    If your instruments' output is actually a square wave, you'd want to use (a) comparator(s) instead of opamps to sense the transitions, as comparators are usually far faster than opamps.
  4. jarek319

    Thread Starter New Member

    Jan 24, 2010
    The instrument is monophonic.

    Would an LM324N be fast enough? The device would have to be single supply and portable, that's why I chose that chip for creating the square wave in the first place, using its Comparator with Hysteresis circuit, found in its datasheet. Or is there a chip which function as a zero crossing detector faster than an LM324N?

    Or should I abandon the LM324N and chips in general and create my Schmitt Trigger with transistors? http://pcbheaven.com/drcalculus/index.php?calc=st_tr
    Last edited: Aug 27, 2010
  5. tom66

    Senior Member

    May 9, 2009
    An LM339 would be faster as a zero crossing detector.

    One way you could do this would be using a LM2907 frequency to voltage converter, and some way to "round" the output voltage, which would then be fed into a voltage to frequency converter. The challenge is the rounding bit; a network of comparators could do this, but would be limited by however many comparators you wanted to use.
  6. Audioguru

    New Member

    Dec 20, 2007
    An MC33171 single opamp, MC33172 dual opamp and MC33174 quad opamp have the same low supply current, the same ability to operate from a single supply as low as 3V, the same ability of its inputs to work at ground and the same ability of its output to go down to ground as the LM324 and LM358. But they does not have the high crossover distortion nor the very low highest frequency.

    The LM324 and LM358 have crossover distortion up to 3%. They have trouble above only 2kHz.
    The MC3317x opamps go easily up to 35kHz and have un-measurable crossover distortion.
  7. SgtWookie


    Jul 17, 2007
    If you really want a square wave output, you'd be better off using comparators. The opamps Audioguru referred to are great, and for audio frequencies, you'd be hard-pressed to tell the difference between those opamps and a comparator.

    However, you can pick up an LM339 at your local Radio Shack. You'll pay quite a bit more than if you bought from a place like Digikey.com, Mouser.com, AvnetExpress.com, however you can get it today and there will not be shipping charges.

    Comparators are related to opamps, in that they both have inverting and noninverting inputs, outputs, and power/ground pins. However, opamps have bipolar compensated outputs, where the most commonly available comparators are not compensated, and have open-collector outputs - which means they can sink current, but cannot source it. You need to use a resistor from +V to the output pin in order to provide a current source.

    For LM339 quad, LM393/LM2903 dual, LM311 single comparators, a source current of roughly 3 to 4 mA works well.

    Compute that by calculating:
    Rpullup = V+ / 3.5mA
    Use the closest standard value of resistance.
    A table of standard resistance values is here:
    Refer to the green columns (E24 values)

    For example, if your V+ is 12v, then:
    Rpullup = 12v/0.0035 = 3,428.
    3,300 or 3.3k is the closest standard value.
    12v/3.3k = 3.64mA - we're in the ballpark.

    If necessary, you can always use/add a voltage follower or the like to increase the output current.
    Last edited: Aug 27, 2010
  8. jarek319

    Thread Starter New Member

    Jan 24, 2010
    Thank you very much for all your help! After failing miserably trying to use the LM339 datasheet to build the actual zero-crossing detector circuit, I used the comparator with hysteresis circuit and it works just as needed.

    Unfortunately I don't have any of the opamps Audioguru suggested, but I will put them on my next Digikey order. Thanks!