the frequency of this triangle wave generator

Thread Starter

Green Bean

Joined Mar 31, 2017
126
Hello again. I have a question about this circuit: http://tinyurl.com/ybcap9jp

ybcap9jp_Green Bean_normal.jpg

I have been experimenting with different values for the components in the circuit, and I was wondering how I could accurately calculate the frequency of the output. From my experimentation, I know that increasing the resistance of R1 lowers the frequency, increasing the resistance of R2 lowers the amplitude, and increasing the resistance of R3 lowers both at once. But what is the formula?


Mods Edit:
Please upload your circuit as 800x600 jpg to the forum.
 

wayneh

Joined Sep 9, 2010
18,091
Hello again. I have a question about this circuit: http://tinyurl.com/ybcap9jp

I have been experimenting with different values for the components in the circuit, and I was wondering how I could accurately calculate the frequency of the output. From my experimentation, I know that increasing the resistance of R1 lowers the frequency, increasing the resistance of R2 lowers the amplitude, and increasing the resistance of R3 lowers both at once. But what is the formula?
Ummm.... You're aware the formula is given in the link you posted, right?

By the way, if you want to try a different simulator, here is the LTspice file for the linked circuit.
 

Attachments

Last edited:

Thread Starter

Green Bean

Joined Mar 31, 2017
126
Ummm.... You're aware the formula is given in the link you posted, right?
No, where?

Thanks. I'd like to build a few of these circuits and I have a few questions about the components.

The schematic on this page uses a TL082 dual opamp. Is there any reason I can't use two opamps of a LM324 quad opamp?

Also, the power supply I am using has only 0v, 3.3v, and 5v. Is it ok to use 0v for the -v pin and +5v for the +v pin?
 

wayneh

Joined Sep 9, 2010
18,091
No, where?
Apologies. The link provided by @bertus contains the formula.
The schematic on this page uses a TL082 dual opamp. Is there any reason I can't use two opamps of a LM324 quad opamp?
You can use any op-amp, however it's required to keep the input and output voltages in the common-mode range of the op-amp. This range of voltages is typically less than the range between the power rails. The LM324 can get you to the ground rail but only to V+ -1.5, or 3.5V on a 5V supply.
Also, the power supply I am using has only 0v, 3.3v, and 5v. Is it ok to use 0v for the -v pin and +5v for the +v pin?
Yup, you just have to bias the input pins to V+/2 instead of ground as you would with a dual supply.
 

Thread Starter

Green Bean

Joined Mar 31, 2017
126
Apologies. The link provided by @bertus contains the formula.
You can use any op-amp, however it's required to keep the input and output voltages in the common-mode range of the op-amp. This range of voltages is typically less than the range between the power rails. The LM324 can get you to the ground rail but only to V+ -1.5, or 3.5V on a 5V supply.
Yup, you just have to bias the input pins to V+/2 instead of ground as you would with a dual supply.
Thanks. I saw your edit, I'll be sure to check out LTspice. I have some more questions, but firstly:

I want to use 36 of these circuits to make a fully polyphonic, 3 octave synthesizer (one oscillator per key, each tuned to a certain frequency with a trimpot in place if R1). That's why I wanted to use quad opamps, to use less chips. I'll have some questions about mixing soon, but what I really want to know is how I can make simple filters for each oscillator? So that the sound builds up in volume, and sustains as the key is held, and slowly decays after it is released. What I had in mind is some sort of gate where there are two inputs and one output. The amount of signal from the oscillator that is allowed through is determined by the other input. I think I could use a BJT transistor and a capacitor somehow, but I'm not sure how to implement it. But I'd like to avoid using another opamp if possible, only two opamps per oscillator. I don't want to be able to control the envelope, I just want consistent attack, sustain and release on every oscillator. Any ideas?

EDIT: Here is a circuit I made: http://tinyurl.com/ybdqbfs7

Screenshot_2017-08-16-14-32-10_kindlephoto-4066325.jpg

When the button is pressed, the capacitor charges. After it reaches its maximum capacity, it stays at that voltage until the button is released. Then it slowly loses charge. This circuit does exactly what I want it to do, but I have no idea how to use it to filter the signal of the oscillators (like I said, I want one of these on every oscillator). My idea was to use a BJT transistor somehow but I don't know where to put it.
 
Last edited:

Thread Starter

Green Bean

Joined Mar 31, 2017
126
Ok, here's what I came up: http://tinyurl.com/ybcz3mcy

The transistor is configured to cut off the signal if it goes above a certain voltage. The cutoff voltage is determined by the voltage on the capacitor. When the button is held, the capacitor charges, "opening the mouth" of the filter (the cutoff voltage rises, allowing more of the signal through). Once the capacitor is fully charged, the entire signal is allowed to pass. When the button is released, the capacitor discharges, closing the filter (the cutoff voltage gradually decays until the signal is completely blocked).

This is great and all, but there are some wacky voltages around the transistor to get it to oscillate between "cutoff" and "saturation". Should I find a higher voltage power supply? Also, are electorlytic caps ok, I mean, its just a filter.
 

wayneh

Joined Sep 9, 2010
18,091
I want to use 36 of these circuits to make a fully polyphonic, 3 octave synthesizer (one oscillator per key, each tuned to a certain frequency with a trimpot in place if R1).
This is a big project. If I were doing it, I'd want to be certain that the end result is what I hoped for. So let's talk about your project goals.

If you really want this thing to be useful for making music, I'm afraid you'll be disappointed. Without a steady and reliable clock, the oscillator frequencies will drift enough to fall out of tune. With 36 of them, you'll probably never get them all in tune at the same time. This drift is caused by temperature variations and probably some other factors that would be hard to control. That's why people use quartz crystal oscillators for the base of any electronic instrument.

For the amount of work you're looking at to complete your project, you could instead get yourself a MIDI keyboard to use with your computer. This would give you almost unlimited control over wave shapes, tones and so on. I think you'd have a heck of a lot more fun with that than a DIY keyboard that's never in tune.

If your goal is to build something, you should at least consider starting with a proven design.
 

MrAl

Joined Jun 17, 2014
13,673
Thanks. I saw your edit, I'll be sure to check out LTspice. I have some more questions, but firstly:

I want to use 36 of these circuits to make a fully polyphonic, 3 octave synthesizer (one oscillator per key, each tuned to a certain frequency with a trimpot in place if R1). That's why I wanted to use quad opamps, to use less chips. I'll have some questions about mixing soon, but what I really want to know is how I can make simple filters for each oscillator? So that the sound builds up in volume, and sustains as the key is held, and slowly decays after it is released. What I had in mind is some sort of gate where there are two inputs and one output. The amount of signal from the oscillator that is allowed through is determined by the other input. I think I could use a BJT transistor and a capacitor somehow, but I'm not sure how to implement it. But I'd like to avoid using another opamp if possible, only two opamps per oscillator. I don't want to be able to control the envelope, I just want consistent attack, sustain and release on every oscillator. Any ideas?

EDIT: Here is a circuit I made: http://tinyurl.com/ybdqbfs7

View attachment 133064

When the button is pressed, the capacitor charges. After it reaches its maximum capacity, it stays at that voltage until the button is released. Then it slowly loses charge. This circuit does exactly what I want it to do, but I have no idea how to use it to filter the signal of the oscillators (like I said, I want one of these on every oscillator). My idea was to use a BJT transistor somehow but I don't know where to put it.
Hi,

Why use a complicated oscillator then if you can use a simple square wave oscillator and filter that instead?
What kind of tonal sound are you after?

I had verified the formula for the triangle generator:
f=R2/(4*C*R1*R3)

however that is when there is a plus and minus supply of equal voltages. This can also be done with a single supply with a slightly different circuit.
 
Last edited:

AnalogKid

Joined Aug 1, 2013
12,071
what I really want to know is how I can make simple filters for each oscillator? So that the sound builds up in volume, and sustains as the key is held, and slowly decays after it is released.
Welcome to synthesizer design in the 60's and 70's. PAIA was the king of hobbiest synthesizers, and their schematics are all over the internet.

What you describe is an ASDR circuit. Attack, Sustain, Decay, Release. At it's heart is either a voltage-controlled attenuator, a voltage-controlled amplifier (VCA), or an analog multiplier. The VCA and multiplier circuit are more complex, but deliver way better results. National Semiconductor and RCA made VCA chips designed specifically for audio circuits.

ak
 

Thread Starter

Green Bean

Joined Mar 31, 2017
126
This is a big project. If I were doing it, I'd want to be certain that the end result is what I hoped for. So let's talk about your project goals.

If you really want this thing to be useful for making music, I'm afraid you'll be disappointed. Without a steady and reliable clock, the oscillator frequencies will drift enough to fall out of tune. With 36 of them, you'll probably never get them all in tune at the same time. This drift is caused by temperature variations and probably some other factors that would be hard to control. That's why people use quartz crystal oscillators for the base of any electronic instrument.

For the amount of work you're looking at to complete your project, you could instead get yourself a MIDI keyboard to use with your computer. This would give you almost unlimited control over wave shapes, tones and so on. I think you'd have a heck of a lot more fun with that than a DIY keyboard that's never in tune.

If your goal is to build something, you should at least consider starting with a proven design.
Hmm. Well my goal is to build something. How difficult is it to make a crystal oscillator circuit for this application (or 36 of them)? What do you reccomend I do?

Hi,

Why use a complicated oscillator then if you can use a simple square wave oscillator and filter that instead?
What kind of tonal sound are you after?
Anything that sounds neat, as far as waveforms are concerned. The most important part is the envelope and full polyphony (I'd like one oscillator per key). I guess I could use a square wave oscillator, but I have heard that the 555 timer drifts with temperature, so that probably would be no good. It looks like I should use crystal oscillators. I have a few crystal resonators, but they are very high frequency. What type of circuit is used to produce audio frequencies?
 

AnalogKid

Joined Aug 1, 2013
12,071
I have heard that the 555 timer drifts with temperature
Beyond the fact that *all* oscillators drift with temperature, the 555 is remarkable stable, especially for its cost and simplicity. On a good day it adds less than 1% error to the calculated timing components. The external component errors and drift far outweigh those of the 555 internal circuit.

ak
 

Thread Starter

Green Bean

Joined Mar 31, 2017
126
Beyond the fact that *all* oscillators drift with temperature, the 555 is remarkable stable, especially for its cost and simplicity. On a good day it adds less than 1% error to the calculated timing components. The external component errors and drift far outweigh those of the 555 internal circuit.

ak
Oh, ok. Would it be more feasible to use 555 timers then (as apposed to crystals)?
 

wayneh

Joined Sep 9, 2010
18,091
I have a few crystal resonators, but they are very high frequency. What type of circuit is used to produce audio frequencies?
The approach is usually to use a high frequency clock and then the different keys select a different "divide by" factor. So to get 440Hz you might start with 1.802MHz and divide it by 4096. I'm sure there is some preferred clock frequency that simplifies the rest of the circuitry. No idea what that is, but I suggest you research that. Since everything is based off a single oscillator, you need only tune that one to get the entire system in tune.
 

AnalogKid

Joined Aug 1, 2013
12,071
Oh, ok. Would it be more feasible to use 555 timers then (as apposed to crystals)?
Only as a learning experience. Nothing will give you the frequency stability of a crystal.

Dividing a single high frequency clock down to the 12 frequencies in a standard keyboard octave is not easy, because the numbers are so weird. Back in the day, several companies made divider chips for keyboard synthesizers.

upload_2017-8-17_16-24-54.jpeg
ak
 

MrAl

Joined Jun 17, 2014
13,673
Hello,

All the notes in the chromatic scale are related by the twelfth root of 2. So if you played all the notes on the piano starting from left to right each note increases in frequency by about 1.06 approximately. The exact ratio has to be accurate however and you can look up the accuracy requirement on the web.

The simplest way to do this though is not to rely on the ratio of each note in the chromatic scale but only on each octave. This way you have to build 11 good oscillators with accurate frequencies that have that relationship, but then just divide them down by powers of 2 to get the all the notes on the piano for example.
You start with the highest frequency you need divided by 2 as the first oscillator frequency, then multiply that frequency by 2^(1/12) and build that oscillator, then multiply it by 2^(2/12) for the next oscillator frequency, then by 2^(3/12) for the next, etc., until you reach the oscillator frequency of 2^(12/12) which is just 2 times the lowest. So you end up with 11 oscillators.
You could also do this by starting at some high frequency like a high A note 4400Hz and just divide by 2^(1/12) until you get down to 1/2 frequency.
For example, if you build an oscillator of 7040Hz that would be a very high A higher than any note on the normal piano, and when you divide it by 2 you get the next octave down 3520Hz A note. Dividing again by 2 you get 1760Hz A note, then 880, then 440, then 220, etc.
That covers all the A notes.
Next you take 7040 and divide it by 2^(1/12) and get 6644.875161279. You then divide that by 2 several times and that gives you all the A flat (G sharp) notes.
Then divide 7040 by 2^(2/12) and do the same thing.
So you build 11 oscillators and use several divider chips to get all the frequencies.

Note this gives you every note on the equal tempered chromatic scale which can be argued can not play every single piece of music ever written especially written long ago. If you need to reproduce notes tempered by 'cents' or if you intend to play some non western music then you may also need to allow for frequency shifts that do not follow any regular division rule. You may even want to include some mechanism for a 'slide' on a non fretted instrument or 'pull' on a guitar.
As a compromise however, the equal tempered scale works pretty well and is used in most modern tuning.
 

Sinus23

Joined Sep 7, 2013
250
Only as a learning experience. Nothing will give you the frequency stability of a crystal.

Dividing a single high frequency clock down to the 12 frequencies in a standard keyboard octave is not easy, because the numbers are so weird. Back in the day, several companies made divider chips for keyboard synthesizers.

View attachment 133156
ak
Here are some of those oldschool chips listed. Not sure where you could find some of those today. http://www.armory.com/~rstevew/Public/SoundSynth/TopOctave/topdividers.html#Fig4

And here you can find a modern equivalent(Polytron37 ) http://www.dspsynth.eu/ Bit pricey though but I guess they don't really sell millions of that chip per year.;)
 
Top