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!

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