# How to Generate a square, sine, and triangle wave with DC input

I want to make a simple synthesizer as a start to audio electronics. I want to start with a simple square, triangle, and sine, which the user can vary the pitch.

Is there a simple circuit to do these? I know a square can be achieved with a 555 timer, but I don't know where to start on sine and triangle.

-
A triangle wave is a square wave integrated. You can build a signal integrator with an op-amp. – dext0rb Apr 5 '13 at 2:04
Which frequency range? By "audio electronics" I assume this is 20 Hz ~ 20 KHz. – Renan Apr 5 '13 at 2:10
basically you need a DAC – martini Apr 5 '13 at 2:15
waz a dac _________ – skyler Apr 5 '13 at 2:25
@Edwin "Pretty choppy" would depend on the synthesis frequency used with the DAC: Many modern signal generators use DDS chips, which generate excellent sine waves using this method. See this tutorial: A quote from it... "a DDS device will include an integrated D/A converter function to provide an analog output signal." – Anindo Ghosh Apr 5 '13 at 2:48

Because the 555 charges the capacitor to 2/3 and discharges to 1/3 of the supply voltage, the extreme parts of the logarithmic curve don't appear. The resulting waveform is an approximation of a triangle wave.

It should sound reasonably close to a triangle wave. This signal can be found at the capacitor on pin 6.

An image search on "sine converter" will turn up a few circuits that convert a triangle wave to an approximate sine wave. There are a lot of parts in them, though.

-
Oh, thats how those dual 555 timer sirens work – skyler Apr 5 '13 at 22:21

If you want to do it using analog parts:

For doing it digitally, I'd consider direct digital synthesis using a microcontroller (as seen here). You can buy ICs that implement this e.g. the AD9835 (breakout board available e.g. from Sparkfun) + a microcontroller to drive it. Then you can add some fancy features (e.g. LCD display, computer control etc...) But that might be overkill for your needs.

A reasonably fast microcontroller with a DAC might be able to do it without a dedicated chip. Do note that if you use a DAC, you will need some analog filtering at the output. At audio frequencies shouldn't be very hard to do, plus you will probably need/want to amplify/buffer the signal.

-
... or the OP could buy a DDS board using the AD9850 for under \$5 with free shipping on eBay.com – Anindo Ghosh Apr 5 '13 at 2:52

By strange coincidence I've just been working on a circuit using a 555 timer to do just that. I needed a low cost, stable, low frequency, variable frequency, constant amplitude linear sawtooth so it could be converted easily to a sinusoidal waveform using a simple resistor - diode circuit.Over many years I've always had a soft spot for the extremely versatile 555 chip It may be old in the tooth (like me) but its still capable of surprises.

First of all the power line connections for the 555 ---- pin 4 and 8 to positive, pin 1 to negative or 0V if single supply. (as normal). See data sheet for you op amp pinouts.

The circuit concept:

(Would have posted the circuit diagram but as a noobee I'm not allowed)

                  --->---555--->--(INVERTER)-->INTEGRATOR--->---
!                                             !  /\/\/\
---<----------------<--------------------<----


If you connect the input of a 'standard (RC, inverting) op amp integrator' to the output pin (3) of the 555 chip you can produce a ' one off ' linear ramp (not particularly useful).

The concept of this circuit is to change the output state of the 555 when the output of the ramp voltage from the integrator reaches fixed levels, a maximum and a minimum.

The 555 has TWO comparator inputs set at 2/3 V (max) and 1/3V (min) (where V is the supply voltage). So by connecting pins 2 and 6 together we can set the upper and lower FIXED voltages for the output ramp voltage (by comparison). Unfortunately the output of the 555 (pin 3) is 180 degrees out of phase with the signal needed. We need to add a simple inverter circuit between the output of the 555 and the input of the integrator in order to make it work as an oscillator.

By symmetry (charging and discharging times are equal if the input voltage voltages above and below the non-inverting input (+) voltage of the integrator have the same magnitude) the output of the 555 is a square wave (1:1).

Hey presto - when the output of the integrator is now connected to pins 2 and 6 on the 555 chip the system oscillates and produces a constant amplitude (1/3V - 2/3V) linear sawtooth wave at the output pin of the integrator. (the capacitor is effectively charged by a constant (bidirectional) current that is proportional to the INPUT VOLTAGE of the integrator)

This ramping output is relatively low impedance - unlike some circuits that try to take the voltage signal from across the capacitor (and alter the frequency). This means that quite small values of C and very high values of R can be used to produce low frequencies (better stability/accuracy).

By using a variable resistor (R) in the integrator we can easily change the output frequency but the upper and lower amplitudes of the wave are FIXED by the two input comparators of the 555.

The frequency (or period) could also be controlled by the value of the output voltage from the inverter (op amp) since charging time is inversely proportional to V(in). (Remember to take into account that is voltage is relative to the non inverting input pin of the integrator).

If you are using a single supply voltage the non-inverting inputs of the op amp should be tied to half the supply voltage (simple potential divider + capacitor), if using a split supply (say 2 x 9V batteries) these inputs should be tied to the mid point (nominally the '0V')

For a single supply voltage (say a 9v battery) the output from the integrator will swing between 3V and 6V with an average DC value of 4.5 volts. For a split supply (9v plus 9V) the swing will be -6V to +6V with an average DC level of 0V. (useful if you don't want to decouple with big capacitors at very low frequencies) To convert to a sinewave - there are many excellent circuits out there - remember to factor in the DC level of the output or use a big capacitor to decouple the DC.

Finally - do you have to use a 555?

No - you could build/design your own high/low comparator circuit using a couple of op amps (or any other suitable technology) and set the switching levels to your own requirements. A quad op amp package could well do everything (perhaps I'll look at that one myself to reduce the package count). Its a very simple circuit - it works - its cheap and I'm certain it can be made to do many more things including linear ramps, vibrato circuits etc, enjoy!

-
Nice ASCII art. – Pete Becker May 10 '13 at 14:20

If you don't have a 555 at your disposal, you can use a Schmitt Trigger to generate a square wave and integrate that to make a triangle wave.

To do a sine wave with DC input, there are various op-amp design techniques you can use. If you are lazy, you can generate a choppy sine wave using a DAC in a micro controller.

A nice book for reference if you are looking into opamp design is: "Design with Operational Amplifiers and Analog Integrated Circuits" by Sergio Franco

You can buy the international edition of the book for cheap.

-

I can recommend you Exar's XR2206 chip. It's a function generator chip which can do all you want. It has a lot of functions on board, which you can select using jumpers or switches.

Here is a circuit with the XR2206 which does sine, triangle and square wave from 20Hz to 100kHz. You can adjust the amplitude and frequency. With more advanced circuits you would also be able to change the duty cycle, but I can't find anything at the moment - refer to the datasheet.

I've built an XR2206 function generator from a (Dutch, unfortunately) magazine and used it successfully for some years. I'm now working on a digital interface to the same thing. You might find this blogpost interesting.

You can of course use a Digital Analogue Converter (DAC) and program a small chip to make the waves you want, but I don't consider that to be a good start to audio electronics. When you want to understand audio electronics, it's better to work with analogue electronics.

Others have mentioned a DDS already. Currently, I'm working on a project with an AD9834, which seems to be a nice chip for the same goals. However, I'm using it for square waves only, so I can't say anything about the quality of the other waves. But others are quite enthusiastic!

-
Sadly the XR2206 is discontinued. :/ – Renan Apr 5 '13 at 17:07
@Renan no! Well, I'll leave this post here for anyone who can find an XR2206 somewhere... – Camil Staps Apr 5 '13 at 17:14

You may also use an Ready I.C. the icl 8038 or the MAX38 whatever company you choose It generates them all from 3 separate outputs.

-
Aren't the ICL8038 and MAX038 both end of life? – PeterJ Nov 24 '14 at 13:52
They are, but at least the ICL8038 is easy enough to find. – Randy Nov 24 '14 at 22:58
Well, honestly; I have no idea because the last time I used them was at the end of 2003!? – MNFsoft Nov 25 '14 at 15:27