Generating Clean 50% Duty Cycle Square Waves

In summary: The waveform is choppy and the sound is uneven. The squarewave generated by the schmitt trigger is not a pure 50% duty cycle wave, it's about 52%, which affects the sound. If you want a pure sound, you should be looking for sinewave circuits.
  • #1
sciguy14
5
0
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:
Engineering news on Phys.org
  • #2
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

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:
  • #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.
 

Attachments

  • P1020176.jpg
    P1020176.jpg
    17.4 KB · Views: 971
  • #4
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.
 
  • #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!
 

Attachments

  • P1020178.jpg
    P1020178.jpg
    16.5 KB · Views: 949
  • #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...
 
  • #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
 
  • #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?
 
  • #9
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:
  • #10
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
 
Last edited by a moderator:

What is a 50% duty cycle square wave?

A 50% duty cycle square wave is a waveform that has a 50% ratio between the time it is in the high state and the time it is in the low state. This means that it is on for half of the time and off for the other half, resulting in a square shape.

Why is generating clean 50% duty cycle square waves important?

Generating clean and precise 50% duty cycle square waves is important because they are commonly used in electronic circuits for applications such as clock signals, digital communication, and pulse width modulation. Any deviations from the 50% duty cycle can cause errors in these applications and affect the overall performance of the circuit.

What methods can be used to generate clean 50% duty cycle square waves?

There are several methods that can be used to generate clean 50% duty cycle square waves, including using a 555 timer IC, a flip-flop circuit, or a microcontroller. These methods involve precise timing and control of the signal to achieve a 50% duty cycle.

What are some potential challenges in generating clean 50% duty cycle square waves?

Some potential challenges in generating clean 50% duty cycle square waves include noise interference, component tolerances, and signal distortions. These can affect the accuracy and stability of the square wave and may require additional measures to ensure a clean output.

How can the quality of 50% duty cycle square waves be measured?

The quality of 50% duty cycle square waves can be measured by analyzing the waveform using an oscilloscope or a frequency counter. The measurements should show a consistent and precise 50% duty cycle with minimal noise and distortions. Additionally, the rise and fall times of the signal can also be measured to ensure fast and accurate transitions.

Similar threads

Replies
16
Views
1K
  • Electrical Engineering
Replies
12
Views
1K
Replies
61
Views
6K
  • Electrical Engineering
2
Replies
38
Views
19K
Replies
38
Views
3K
Replies
47
Views
3K
Replies
15
Views
2K
  • Electrical Engineering
Replies
20
Views
3K
  • General Engineering
Replies
3
Views
3K
  • Electrical Engineering
Replies
10
Views
5K
Back
Top