Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Generating Clean 50% Duty Cycle Square Waves

  1. Aug 12, 2010 #1
    Hey all!

    I'm trying to drive 5 speakers, each at a different preset frequency. I had been using the timer in my microcontroller to drive one, but it would get very messy to drive 5 simultaneously in software using just the 1 available timer. I've decided to drive each with a Hardware-generated squarewave instead.

    I figured the easiest way to do this would be to simply use a circuit like this one:
    tim29.gif

    I'm using an ST M74HC14 Hex Schmitt Inverter for the job. This should theoretically generate a really nice 50% duty cycle square wave. Unfortunately, my speaker seems to disagree. When I drive it via my microcontroller timer I get a nice clean tone, but with this wave, the tone is uneven sounding and a bit choppy.

    So, I looked at the two square waves on an oscilloscope. They both looked almost identical except for one thing. The timer-generated wave was precisely 50% duty cycle, whereas the trigger-generated wave was about 52% duty cycle.

    Looking more closely at the datasheet for my Schmitt Inverter, I noticed that the output switch wasn't perfectly symmetrical, which is probably the cause the slight duty cycle issue. Here is the datasheet: http://www.st.com/stonline/books/pdf/docs/1901.pdf

    So here are my questions:
    1. Can a error of only 2% really drastically affect how the speaker sounds?
    2. Could this be resolved by moving to a slightly more accurate Schmitt Inverter like this one: http://www.fairchildsemi.com/ds/MM/MM74C14.pdf ?
    3. Is there some other way that I should be driving these speakers that I don't know about? (I've tried an op-amp square wave generator circuit with little luck using single supply). I also know that a 555 timer is a common choice, but you can't get to 50% exactly with that.

    Thanks for any feedback!
     
    Last edited: Aug 12, 2010
  2. jcsd
  3. Aug 12, 2010 #2

    vk6kro

    User Avatar
    Science Advisor

    Were you driving the speakers directly with the Schmit trigger output?
    Speakers are only 8 or 15 ohms, so the trigger would not work too well with such a low resistance load on it.

    This circuit generates a good 50% duty cycle square wave, but you need to use a CMOS 555 like a TLC555 or a 7555:

    [PLAIN]http://dl.dropbox.com/u/4222062/555%20Osc.JPG [Broken]

    However, you would need to use a suitable audio amplifier to drive a speaker with the output.

    The difference between 50% and 52% duty cycle would not make any difference to the sound.

    If you want a pure sound, though, you should be looking for sinewave circuits.
     
    Last edited by a moderator: May 4, 2017
  4. Aug 12, 2010 #3
    I'm not driving the speaker directly. The square wave goes through a variable resistor (to control volume) which then goes to the base of a darlington transistor. 5V flows through the darlington, through a 50ohm resistor, then through the speaker to ground.

    I'll pickup a CMOS 555 from radioshack tomorrow, and I'll try out the circuit you attached.

    I was under the impression that speakers needed to be driven with a square wave. If I should be driving it with a sinusoidal wave, what kind of circuit should I be using? I obviously want the tone to sound as nice as possible.

    If the 52% duty cycle didn't make a difference, then what could be the reason for the speaker sounding worse when the signal comes from a schmitt trigger instead of a microcontroller?

    Here is the circuit I'm using right now.
     

    Attached Files:

  5. Aug 12, 2010 #4

    vk6kro

    User Avatar
    Science Advisor

    All waveforms except sinewaves are made up of two or more sinewaves which consist of a sinewave at the fundamental frequency plus other sinewaves at multiples of this frequency.

    So, a sinewave gives a very pure, if boring, sound. Like a violin, sort of.

    That circuit would work for square waves although strictly you should not pass DC current through a speaker.
    You should use a proper audio amplifier. I guess Radio Shack would carry the LM386 chip. This can drive a speaker properly and not add extra distortion provided you do not overdrive it. It needs some extra components so you need to get a list of these before you go.

    One chip can handle more than one sinewave at a time provided you keep the individual levels low. It only has one output, though, so all sinewaves would come from the same speaker.

    Generating sinewaves is surprisingly quite difficult. However there are some circuits that can do it.
    This site has lots of such circuits:
    http://www.discovercircuits.com/O/o-sine.htm

    If you have access to an oscilloscope, maybe you could use an audio signal generator to produce sinewaves. This is a very useful instrument and you can use it to detect distortion in amplifiers. If the input is a sinewave and the output is not, then the amplifier is distorting the signal.
     
  6. Aug 12, 2010 #5
    Thanks for the help so far! I'm going to stick to a squarewave if it's easier. It doesn't need to sound concert quality :smile:

    I happened to have an LM386 laying around, so I set up the circuit in the attached schematic.

    When I use the schmitt trigger squarewave generator (as in the schematic) the speaker just hums a bit at a low volume. It doesn't not change volume at all as I adjust the potentiometer.

    If I drive it from the microprocessor's timer squarewave output (the method that I will NOT be using in the final design), I get a pretty nice loud tone, though it still does not change volume as the potentiometer is adjusted.

    Thanks again for all your help!
     

    Attached Files:

  7. Aug 12, 2010 #6
    To get a PrettyGood(TM) 50% duty cycle -- presuming that your master oscillator has a nice stable frequency -- you could use a flip-flop to divide by 2.

    Not sure what kind of software you tried, but a PIC chip could generate many simultaneous PrettyGood(TM) squares using a fairly high speed timer and a bunch of counters. If you are looking to have multiple oscillators at very specific -- and constant -- frequencies, that might be the best solution.

    As to the 2% off problem, a 50% square wave has (IIRC) all the odd harmonics with linearly descending volumes. Changing the duty-cycle has a fairly dramatic effect on the harmonic content, but I don't remember an exact relationship. If you have the technology, an FFT would probably show what's going on. Also, again IIRC, a bowed violin string is more of a sawtooth wave because the bow repeatedly grabs, pulls, and releases the string. A decaying string tone, after the bow is removed, is closer to a sine.

    A good compromise, if you get tired of square waves, is a triangle wave. Very close to a sine with a bit of high harmonics but PrettyEasy(TM) to generate...
     
  8. Aug 12, 2010 #7
    Thanks for the tips. I don't really care what kind of wave it is, so long as it sounds decent on a simple 8ohm or 4ohm speaker. I'd be nice if I could get this going with parts I already have, which include schmitt triggers, op amps, audio amps, transistors, and a digital pots (plus resistors and caps of course). I'd like to avoid driving these via a microcontroller - a purely hardware circuit would be ideal.

    Can you (or anybody) suggest a complete circuit that will both generate the wave at a particular frequency and allow me to change volume using a digital potentiometer?

    Much obliged,
    Jeremy
     
  9. Aug 12, 2010 #8
    I've tried the CMOS 555 circuit you posted above, still without luck. The speaker tone is just very "buzzy" instead of the nice solid sound when I use the micro's timer. I even removed the volume control to ensure that wasn't the issue.

    I'm totally at a loss here. Could I try using some kind of h-bridge setup to generate a sinusoid to drive it over it's full range?
     
  10. Aug 12, 2010 #9

    vk6kro

    User Avatar
    Science Advisor

    The 386 amplifier has a 100 ohm resistor in series with the speaker. This would be dropping the output to about 7% of its full capability.

    Also, you could take the output of the Schmitt circuit via a 100 K resistor and a 0.1 uF capacitor in series. You would be grossly overdriving the 386 at present.
    Omit the 10 K resistor in series with the pot. Put the pot in so that it is grounded at one end. Take the output from the moving contact of the pot directly to the 386.

    You can get a better sound from the Schmitt circuit if you take it from the 0.1uF capacitor where it joins the 45 K resistor. This should be approximately a triangular wave. You should be able to observe this waveform with your oscilloscope and see if it gets distorted in the amplifier.
     
    Last edited: Aug 12, 2010
  11. Aug 12, 2010 #10

    vk6kro

    User Avatar
    Science Advisor

    Also, the 10 uF capacitor at the output of the 386 is too small. I would suggest about 470 uF or bigger.

    Like this:

    [PLAIN]http://dl.dropbox.com/u/4222062/386%20amplifier.PNG [Broken]
     
    Last edited by a moderator: May 4, 2017
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook