A simple oscillator

What is an oscillator?

In electronics an oscillator can be described as a system that turns some constant (current or voltage) into a time dependent signal. Often with two distinct states, up and down, high and low, rising and falling, etc...

Now why would you want a circuit like this? Well in our case the goal is to make music, and it just so happens that the thing that we perceive as sound is air pressure waves that oscillate at specific frequencies. So if we hook up one of these circuits oscillating at a specific frequency to a speaker we turn the signals it creates into pressure waves which allows us to listen to it.

Lets design a simple one

To change a constant signal into a time dependent signal we're going to need something that can be charged over time. Think of a battery, when it's full it has a high voltage. Then as it gets drained the voltage drops. When the voltage drops to a certain point the battery stops working properly and you charge it. This cycle repeats itself indefinitetly (or until you stop recharging it). So in a way a battery and a user that keeps recharging it can be seen as an oscillator, just a very slow one.

As it turns out there are a few core components needed to create an oscillating system. You need something that can be charged and discharged over time, something that can see when the voltage is too low or too high, something that can change the direction of charge based on this voltage and some way to remember whether your next state is supposed to be charging or discharging.

To create an oscillator that can oscillate at a higher frequency we're going to need something that's slightly faster at charging and discharging than a battery, a capacitor! 

Lets consider the following circuit. It uses some ideal components and how exactly the direction of charge is reversed isn't quite made clear yet. However we can already deduce how it oscillates.

It makes use of a comparator, a current source and a capacitor. Lets see what happens when the output of the comparator is high.

When the output is high the current source charges the capacitor until the voltage across the capacitor is higher than the output voltage of the comparator. This causes the comparator to change its output to the low state. This should also reverse the current causing the voltage across the capacitor to drop until it is lower than the low state output of the comparator. Which causes the cycle to repeat itself. 

So in this case the capacitor is the thing that can be charged and discharged over time. The thing that can see whether the voltage is too low or too high is the comparator. The direction of charge is controlled by the current source. And the remembering is done by the positive feedback from the comparators output to its input. 

Lets try this with some actual components 

Alright so now that we've got an understanding of what we need lets try this with some real components. 

The charging and discharging is done trough R4 and the output of the comparator. The positive feedback from the output of the comparator trough R3 makes sure that it remembers its states. 

However since the capacitor voltage will never be as high as the output voltage of the comparator. (This is because the capacitor and R4 make a voltage divider) we can't directly hook up the output of the comparator to the negative input. We need to somehow make the voltage smaller when it's in the charging cycle, and make it a bit higher when it's in the discharging cycle.  

To do this we can make use of a voltage divider (R2 and R3) and pull up resistor (R1), this makes sure that the positive input voltage of the comparator is smaller than the comparator output when it's high, and higher than the comparator output when it's low

So lets once again consider what happens when the comparator output is high. The capacitor C gets charged through R4 until the capacitor voltage (which is also the negative input voltage of the comparator) is higher than the positive input voltage of the comparator. This causes the output of the comparator to go low which in turn causes the capacitor to get drained through R4 until the capacitor voltage is lower than the positive input voltage. This cycle repeats indefinitetly. If we keep track of the capacitor voltage, the positive input voltage and the comparator output voltage it will look something like this: 

With the red line being the comparator output voltage, the black triangle shaped line being the capacitor voltage and the dotted V+↓ and V+↑ lines being the comparator input voltage in both the charging and discharging cycle. 

How do we calculate the voltage to frequency ratio? 

So we've got our schematic and made sense of how it works. But how do we know what part values to pick to make sure it's in the audible range?

One thing to try is to just grab some parts and see what happens! then by tweaking the value of R4 you can get a pretty good estimate of where you want that value to be for a given value of C. However if we truly want to grasp how the system transfers the input (in this case the resistor R4) to the output frequency we'll have to calculate the transfer function. 

Lets start by trying to figure out what V+↓ and V+↑ will be, these are decided by the resistors R1, R2 and R3. 

If we see the output of the comparator as a voltage source and the supply voltage as another then the resistor network of R1, R2 and R3 can be described as the following schematic. 

To solve for the node in the middle (the voltage at the positive input of the comparator) the superposition method can be used. This method first calculates what the node would be if the VSS source was a short circuit, then what the node would be if the Vcomparator source was a short circuit and finally adds these two values to get the result of what the nodes value actually is. 

This results in the following equation, the double vertical line indicates that the resistors are parallel. 

The voltage over the capacitor or V- can be described as follows:

V is in this case the voltage across the capacitor, C the capacitor value and R the resistor through which it is charged, in our case R4.

Lets consider what the voltage across the capacitor is at the moment of a state transistion. When the system goes from discharging to charging, the capacitor voltage is at V+↓, the voltage difference from V+↓ to VDD can be described as V. The capacitor voltage V- can then be described as 

Now the system will transition to the next state once this voltage is equal to V+↑ which can be described as:

This will solve for a value of t that is exactly half the period of our signal, since it represents the time it will take for the voltage to rise from the one transition point to the other.  

lets make one final change to this equation before we solve it, if we call V+↑ - V+↓ the hysteresis voltage or Vh the equation turns into:

Now lets solve for half the period time (t), then multiply that by two to get the period time T and finally get the frequency by taking 1/T: 

Cool, we've got our transfer function. However this transfer function does make a few assumptions, for one it assumes that the voltage difference across the capacitor is equal in the positive and the negative cycle. This of course does not have to be the case, however this can be achieved if R1 is equal to R2. 

Another assumption that it makes is that the switching between states is instant, in reality this is limited by the propagation delay of the comparator. In other words, this equation only works as long as tpropagation is way smaller than T.




Allright lets put these equations to work and try and find some proper values. You can use this desomos graph to play around with the values and see the resistance to frequency ratio. 

The values I've chosen are 10nF for the capacitor, 50k for R1 and R2, 5k for R3 and a value between 1k and 1Meg for R4, or in other words a 1Meg potentiometer in series with a 1k resistor. 

Time to simulate and test the circuit!

Now that we've thought out our circuit and decided on our part values we can run some simulations in LTspice (or any other simulator software) the schematic used in LTspice can be seen here.

After running the simulations we find that the calculated transfer function is a reasonable approximation of our circuit. Let's build it in real life!

To do so lets first pick some parts, in our case we'll just see what we have lying around. We're going to make use of an MCP6542 for the comparator. After grabbing our breadboard and looking at what pins correspond with the inputs and outputs of the comparator in the datasheet it's time to build the schematic!

After we're done building it on a breadboard we can check if the system works as intended by hooking it up to an oscilloscope. In our case we've got a picoscope which can be plugged into our computer. 

As we can see here the output behaves as expected! 

Where to go from here

Allright well if you've followed along you'll now have an understanding on what is needed to create an oscillating system, however this doesn't quite let you make nice music yet. For that we're going to need voltage control! Check out our next blog and follow along to start making your own synthesiser! 

Bram de Wit -feb 2023