Step Response in RC Circuits

In passing I’ve referred to the fact that capacitors and inductors are time-dependent components but I never really gave any explanation of this assertion. I’d like to go over a simple case of time-dependent circuitry to clarify exactly what this means and how it differs from time-independent circuitry (resistors, diodes ect.).

Step Response?

Time dependent circuits in a nut shell are circuits which respond to changes in voltage or current over time. These changes can come in many forms but the easiest to wrap your head around (and do the math for) is a step. A step simply refers to any time the voltage (and by extension the current) in your circuit immediately changes from one value to another.

The most basic example of this is when you turn on a power switch on a device. The voltage in the device before the power was connected is typically 0V and after the switch is turned it immediately jumps to the devices operating voltage.

When we look at how the circuit responds to this change (i.e. how the current and voltage in different parts of the circuit change after this step occurs) we are looking at the step response. In a simple resistive circuit the change occurs immediately throughout the circuit however once you introduce capacitors and inductors the story gets a little more complicated.

RC Circuit?

A Simple RC Series Circuit

An RC Circuit is a circuit which contains only resistors and capacitors. These Resistors and capacitors can be arranged in series, parallel, or some combination of the two.

Capacitors

Before we get into the math it’s important to understand some of the properties of capacitors to understand how they react in circuits. A capacitor is made up of two conductive plates separated by a non-conductive layer referred to as a dielectric. These plates collect charge as current flows through the capacitor. When there is no charge on the plates current flows freely through the capacitor but as charge builds less and less current can pass through.

Once a capacitor becomes fully charged no current can flow through it and it behaves as an open circuit. Going back to our power switch example, when the power is off there is no charge on the capacitor. Once the switch is turned the current begins flowing around the circuit. This charges the capacitor until it reaches steady state. When the capacitor is fully charged no current flows and the voltage across the capacitor is maximized.

Math Time

Step Response Equation for RC Circuits

Wait! Don’t run, I promise it’s not as bad as it looks. There is a fairly satisfying calculus derivation for this equation but in the interest of keeping things high level I’ve skipped right to the final formula. That means all we have to do is find values for the unknowns above and we can plug them right in. So how do we find these unknowns?

The Time Constant – The first thing we want to find is a value called the time constant. This represents the speed at which the circuit reaches steady state. The time constant is R*C. The negative of the time is divided by the time constant in the exponent. We simply plug in the resistance and capacitance values from the circuit and we’re all set.

Vo – Vo is the starting voltage of the circuit. This would be the voltage before the step takes place. In our basic switching example this would be equal to 0V since there is no voltage across the capacitor before the switch is flipped.

Vs – Vs represents the steady state voltage. This would be the voltage in the circuit after a long time has passed (Once the capacitor is fully charged). To find this we can replace the capacitor with an open circuit and determine the voltage between the two points.

Now that we’ve defined these variables lets have a look at an example to see them in action.

Example

Example Circuit

Above is a basic example of a simple RC circuit. What we want to find out is how the circuit responds when the switch is closed at t=0. If we complete the equation given above for this circuit we can find the voltage at any time after the switch is flipped by entering the desired value of t.

The first thing we can fill in is the time constant. As I said above the time constant is equal to RC. This would be (10*100uF) for our circuit. Converting uF to F gives us 10*0.0001 and taking the inverse of this (since time is divided by it) gives us 1000. You can see above I have filled in this value above the exponent.

Next up is Vo. For a simple series circuit like this this step is very easy. Before the switch is closed the battery is disconnected from the circuit so no voltage is present in the circuit. This makes Vo equal to zero and it can be removed from the equation.

Finally we can calculate Vs which represents the steady state voltage of the system. Remember that when the capacitor is fully charged it allows no current to flow through the circuit. Since the voltage drop across a resistor is defined by Ohm’s Law (V=IR) and there is no current flowing through the circuit, there is no voltage drop across the resistor. This means the steady state voltage across the cap is the full battery voltage (9V).

Now we’ve got a fully defined function for the voltage at any time after t=0. The trick here is that the exponent (e^(-1000t)) becomes smaller the larger t becomes. This means the more time that passes the larger the voltage becomes until it reaches steady state. Graphing this function we get the following:

NAND Drone

NAND Drone Synth

I’ve built a lot of square wave synthesizers. They are some of my favorite projects. They’re generally fairly straight forward but can provide hours of fun. Further they provide a great starting point for newcomers to audio electronics. That being said after stringing together so many 555 timers and 40106 inverters I was looking for a way to breath some new life into these builds. I decided to start playing with some simple digital logic to see if I could develop a deeper sound while still sticking with basic square oscillators. What I came up with was a super-simple drone synth using NAND gates to combine three 40106 oscillators.

Parts List:

2 – 40106 Hex Schmitt Inverter ICs (One will work but 2 is ideal)
1 – 4011 Quad NAND Gate IC
3 – 0.01 uf Capacitors
3 – 500K ohm Potentiometers
6 – 20K ohm resistors
3 – 10K ohm resistors

Pretty short parts list right? This one comes together pretty easy thanks to the 40106 oscillators low parts count. Even with so few parts though, it still sounds awesome. So lets have a look at the circuit.

Circuit Diagram

NAND Drone Synth Circuit Diagram

Note : I’ve split the 40106 inverters between two chips. Since the 40106 includes 6 inverters this can be completed with 1 40106 chip. However, the 40106 can act unpredictably when all 6 inverters are switching at high speed so the behavior may not be optimal.

This circuit can be split into a few simple parts which I’d like to have a look at seperately.

Square Wave Oscillators

This circuit uses 3 40106 Inverter based oscillators. I used these oscillators primarily for their relative simplicity though essentially any square source could be fairly easily implemented in this design. I used a 0.01uF capacitor to set the frequency range for the oscillation but feel free to experiment with other values to get the frequency you desire. I then limited the current using a 500K ohm potentiometer to allow me to move through a wide band of frequencies.

Buffers

After the square wave is created each signal is passed through an additional inverter. The frequency of the 40106 oscillator is defined by the charging speed of the capacitor. This capacitors charging is a directly result of the current flowing out of the output and through the resistor. This means any addition power draw we add to this output will impact the frequency. To avoid this we send the signal through the additional inverter which isolates any further components from the oscillator circuit.

Attenuation

Next up we pass each signal through a basic voltage divider. This is simply to lower the amplitude of the inverter outputs before sending them into the 4011 Quad NAND chip.

NAND Gate

Here’s where the magic happens! The signals are each connected to two of the NAND gates such that each NAND gate has a unique set of two input signals (Sounds a bit weird but should be clear if you look at the circuit diagram). These NAND gates will be high by default but will go low when both inputs are high. This means any pair of your oscillators going high at the same time will cause at least one of the NAND outputs to go low.

Mixer

Finally we send each NAND output through a 10K ohm resistor and combine them into one output line. You can then wire this to the output style of your choosing and start making noise. Note the output from the 4011 is fairly low amplitude (about 1.5V peak to peak) so you may need to amplify it before connecting to a speaker.

Bigger is Better

I chose to use three oscillators here for convenience however there is no real need to stop there. Just be aware as you grow the number of NAND gates needed to have every combination will grow very quickly. For 4 oscillators you would need 6 NAND Gates, with 5 you would need 10 and so on.

Sound Waves

I just wanted to finish off by showing some of the sound waves I captured on my oscilloscope to give you an idea of what this circuit outputs:

Digital Logic

Working with digital logic may seem counter intuitive to the idea of sound synthesis. Audio is an analog phenomenon and as such we typically steer towards analog electronics to produce or manipulate it. That being said digital electronics can be incredibly valuable to us as synth enthusiasts. We can use them to breath new life and depth into humble square wave oscillators, control analog devices and interface with micro-controllers/processors. For this reason I wanted to provide an introduction to some of the more common digital logic devices you may encounter.

Digital Vs. Analog

Before going too far I’d like to reiterate the difference between analog and digital signals. An analog signal is a signal which varies across a range of voltages. Think of a sound wave, the wave is a continuous signal which rises and falls based on the intensity of the sound being captured.

A digital signal on the other hand varies between two discreet states. The signal is either high or low (0 or 1). Electronically speaking these two states are typically (though not always) 0V for low and 5V for high. Any values between these two states will either be assumed to be one of the two or ignored depending on the components used. The square waves we have produced using 555 or 40106 oscillators could be considered as digital signals as they oscillate between two distinct values.

Truth Tables

Truth Table for a Generic Inverter

Truth Tables are a tool we use to clarify the function of digital logic. The tables show a listing of all possible inputs to the system and the output which they would provide. In the inverter example above (and most of the components I will discuss today) these tables are quite straight forward however as you get into progressively more complicated digital circuits these truth tables will also become more complex.

Building Blocks

Once you have a digital signal whether its from a humble square wave oscillator or something more complex like a microprocessor, there are a number of operations you can carry out on it using digital logic chips. There are hundreds of different chips available but most of them fall into a few basic categories.

NOT Gate:

NOT Gates (commonly called inverters) are probably the most basic digital component you will encounter. As the name suggests they invert whatever signal you send to them. This means if you send in a 1, you will receive a 0 from the output. Alternately if you send in a 0 you will receive a 1. The 40106 I have used in previous projects is a special type of inverter which uses threshold voltages to interpret analog inputs.

AND Gate:

An AND Gate is a digital logic gate which takes two inputs (notice there are now two input columns on the truth table). The output of the gate is only high if both these inputs are high.

NAND Gate:

The NAND gate is actually a combination of the AND gate and the Inverter. Notice the circuit symbol is that of the AND Gate with the small circle from the inverter added. This small circle is used in circuit symbols to indicate that an output is inverted. This means the output of the NAND gate is opposite the output of the AND gate (as seen in the truth table). A NAND gate will output high at all times except when both inputs are high.

OR Gate:

The OR Gate is a gate which will output high when either (or both) of the inputs are high. This can be very useful for combining signals or triggers from multiple sources. There are also a few modified versions of the OR gate which I will look at next.

NOR Gate:

Similar to the NAND Gate this is an OR Gate with an added inverter. This means the NOR Gate will output high when no inputs are sensed. It will go low when Either (Or both) Inputs go high.

XOR Gate:

The XOR Gate is another special type of OR Gate. This time the output will go high when either input is high however if both inputs go high the output will go low.

This is by no means an exhaustive list but should give us a starting place to work from. We can also create progressively more complex gates by combining these different building blocks together. I hope this has given you some ideas about what you can accomplish using digital logic. Keep an eye out for more projects using these gates coming soon!

Voltage Dividers

Voltage Divider Circuit

In many of my past projects I have made use of a circuit component (or set of components) called a voltage divider. I realized however, I’ve never really spent time talking about what these were or how they work. For that reason I wanted to spend some time showing this trick and how you can use it yourself.

So What Are They?

A voltage divider divides voltage! Brilliant analysis I know, but what does that mean? And why is it useful? Simply put a voltage divider is a way to get a smaller voltage from a larger one. For example lets say you are trying to power a chip which requires a 5V power source from a 9V battery. In this situation you could use a voltage divider at the power pin to lower your 9V supply to the required 5V. Another important use is signal attenuation. As we’ll soon see the output of a voltage divider is a linear function of the input voltage. That’s a fancy way of saying the voltage you get out will always be a specific fraction of the voltage you put in (Based on the resistor values). That means if you have a waveform or audio signal you can reduce its amplitude while still maintaining the original waveform.

Note: Voltage Dividers are a cheap and easy way to reduce voltage however they are not highly stable or accurate. If you require a stable supply it is better to use a voltage regulator IC or Buck Converter

Math Time!

Voltage dividers are an excellent illustration of Kirchoff’s Loop Law and we can use this along with Ohm’s Law to calculator our output voltage given the values of R1, R2 and the input voltage.

Voltage Divider Drawn as Loop Circuit

To clarify how these calculations are done I have drawn the divider as a loop with a voltage source V1. We know from Kirchoffs Laws that the Sum of the voltages around any closed loop is zero. This means V1 minus the voltage lost across the two resistors is 0. This also means the voltage V2 will be equal to V1 minus the voltage lost across R1:

To determine the voltage dropped across R1 we can rely on Ohm’s Law. Ohm’s Law states that V = IR. From this we know the voltage dropped across R1 is equal to the product of the resistance and the current. Unfortunately we still need the current for this equation. Looking at the loop as a whole though we can solve for it:

Now that we have an equation for current we can substitute this into the equation for the voltage drop through R1:

Finally we can input this new function into our original equation to solve the ratio between V1 and V2:

We can divide both sides by V1 to clean this up a bit:

For good measure we can do a little more simplification to come to the final voltage divider equation:

And there you have it! using this equation you can take any input voltage and any desired output voltage and calculate the values of R1 and R2 you will need to accomplish that reduction.

40106 Oscillator Continued

40106 Oscillator Schematic

I left my last post (40106 Triangle Waves) on a bit of a cliff hanger. I had shown how to pull a triangle wave from the circuit and identified some issues with the oscillator as it stood. Today I’d like to go over those issues and how I corrected them to get this oscillator up and running.

I do want to mention the oscillator design above is still in a somewhat rudimentary form. I expect there will be quite a bit of optimization that can be done on it as time goes on.

Buffering

Since we are pulling our outputs directly from the loop which sets the frequency, any elements we add to the circuit which draw current will affect the frequency. This is not ideal. What we need to do is isolate the oscillator circuitry from any further additions to the circuit. For the square wave this is extremely straight forward. Since the signal is binary (digital) we can simply send the output through a second inverter on the 40106 chip. Take note: this will invert the signal (when the original oscillation was high the buffered oscillation will be low) however since this is a repeating signal it won’t cause any impact.

The triangle is slightly more difficult to buffer since we need to concern ourselves with a range of analog values. I accomplished this by feeding the signal through an LM324 op-amp set up as a voltage follower with an additional 10uF capacitor on the output.

Amplification

After the buffering stage I was still left with dramatically different amplitudes for the two wave forms. The square wave after the buffer sat at almost 9V while the triangle was only 1.4V (The output voltage of the LM324). There’s a number of ways you can approach this inconsistency however I found myself somewhat limited by the parts I had on hand and by my decision to run this oscillator on a single 9V battery supply.

How I ended up overcoming this was by using voltage dividers to lower both signals to about 1V peak to peak. From here the selected input is sent into a very basic LM386 power amplifier.

This solution does introduce a large amount of noise into the square wave signal so you may choose to bypass the amplifier with the square wave and only use it on the triangle.

Set up this way I got both signals to reliably output approximately 5Vpp.

Decoupling

One issue I ran into a lot with this circuit, especially building on breadboards was noise. The frequency would bounce around and the wave-forms would not be crisp. This can be largely overcome by adding decoupling capacitors between the negative and positive supply lines. An excellent overview of decoupling (and many other common capacitor uses) can be found over at SparkFun.

40106 Triangle Waves

Recently I completed a post discussing the 40106 Inverter and a simple square wave oscillator. I wanted to build on that post a little more today and look at how we can modify this same oscillator to output triangle waves along with square. These triangle waves will sound profoundly different than square waves in the audible range, giving our oscillator 2 distinct voices. Additionally, we can use the oscillator at a low frequency to drive a voltage controlled amplifier or filter. We can get much more variance from the rising and falling triangle wave in these applications than we would with the simple switching of a square wave.

So Where Are These Triangles?

40106 Oscillator with Triangle Output

If you read my previous post you may remember that this oscillator works by charging and discharging a capacitor. As the capacitor charges and discharges it allows the voltage to rise and fall at the input. This rise and fall causes the output of the inverter to turn on and off producing the square wave. What we can also do is take an output at the input of the inverter where the voltage is rising and falling to produce a triangle wave!

An Amplitude Problem

If you try building this circuit as is you’ll very quickly notice an issue with the design. Connecting a speaker to the output of the square wave sounds great but the triangle is barely audible! If you look at the two waveforms above you’ll see that the square wave has a peak to peak voltage of 6.32V. The triangle however is only registering a fraction of that at 1.22V. This is because the output of the inverter (where we draw the square) always outputs a full digital signal. Meanwhile the voltage at the input only rises until it reaches a threshold voltage. At that point the inverter changes state and the capacitor begins discharging again. In this case (running the 40106 on 9V) that threshold appears to be 1.22V.

So What Now?

In my next post I’ll be exploring the use of op-amps to buffer these outputs and equalize them to a usable voltage. Once we’ve accomplished this we’ll be able to start using this oscillator in all kinds of awesome projects. See you all soon!

40106 Hex Schmitt Inverter

The 40106 Hex Schmitt Inverter is an incredibly useful and popular IC in the world of DIY synthesis. It is cheap, easy to use and is central to one of the simplest oscillators around. Today I’d like to have a look at this chip, explain how and why it works and show you how you can use it to start making some noise.

A Hex Schmitt What-Now?

As the name suggests the 40106 chip is a Hex Schmitt Inverter (Or 6 Hex Schmitt Inverters) on a 14 pin chip. An Inverter is a digital component which takes an input (0 or 1) and outputs the opposite value. Typically in digital electronics these would be represented as 0V or 5V meaning if 0V is sent to the input 5V will be output by the output and vice versa. What makes a Hex Schmitt Inverter special is its capacity to take analog inputs rather than just 0 or 5V. The way this is accomplished is by setting a threshold voltage where the output changes. Looking off the datasheet for the 40106 we can see that in typical operation this happens at 0.9V when the chip is being powered with 5V or 2.3V when being powered with 10V. When the voltage on the input goes above that threshold the output turns off. When the input goes below that threshold the output a digital high voltage (usually 5V).

Dividing By Zero?

This Isn’t Going To Work

That probably all sounds as clear as mud so lets go over a simple use case to see if we can make some sense of it. We know that when you input a high voltage to an inverter it outputs a low voltage and vice versa. So what would happen if we connected the output back to the input? Now we’ve built a bit of a paradox! When the output is high it sends that high signal back to the input which makes the output low which makes the input low which makes the output high which makes the output low which makes…. you get the idea. The problem is since this is happening instantly its faster than the chip can handle and the whole thing breaks down.

Capacitor To The Rescue!

Simple 40106 Oscillator

What we need is a way to delay the signal traveling from the output back to the input so we can get a consistent oscillation. We can accomplish this by adding a capacitor between the input and the ground and a resistor between the output and input. The capacitor is initially in its uncharged state and the input is low. This low input voltage causes the output to go high, however an uncharged capacitor provides no resistance between the input and ground so all current flowing out of the output goes to ground and the voltage stays at 0V at the input.

As current flows into the capacitor it begins to charge which in turn resists more current traveling through it. This new resistance allows the voltage on the input to begin to grow proportional to the resistance provided by the capacitor. Eventually this voltage will reach the threshold voltage of the inverter and cause the output to go low. Then the whole thing happens in reverse, as the capacitor discharges the voltage drops until it falls below the threshold voltage and the output switches back to high.

The resistor functions to limit the current traveling from the output to the capacitor which slows the charging of the capacitor.

So How Do We Control This Thing?

Simple 40106 Oscillator with Control Pot

The key to taking this from a curiosity to something useful is control, we need to be able to select a frequency range and modify it in real time. Since the speed the inverter flips from high to low and back is governed by the charging and discharging of the capacitor we can control the frequency by controlling the speed the capacitor charges and discharges.

The first way to do this (as you may have guessed) is by changing the size of the capacitor. A smaller capacitor will charge quickly providing you a very high frequency while a larger capacitor will charge slower and provide a substantially lower frequency. Choosing the right capacitor is a great way to select a range of frequencies for your oscillator however as variable capacitors are rare and expensive this is not an ideal method for making real time changes to the frequency.

This leads us to the second method which is adjusting the resistance. This resistance limits the current flowing to the capacitor. The less current flowing to the capacitor the slower it will charge. Further since potentiometers (variable resistors) are common components we can add a knob to adjust the frequency of our oscillator on the go.

An easy way to calculate the approximate frequency with any resistor capacitor combination is using the equation f = 1.5/RC