# Logic Noise: More CMOS Cowbell!

Logic Noise is an exploration of building raw synthesizers with CMOS logic chips. This session, we’ll tackle things like bells, gongs, cymbals and yes, cowbells that have a high degree of non-harmonically related content in them.

## Metallic Sounds: The XOR

I use the term “Non-harmonic” in the sense that the frequencies that compose the sound aren’t even integer multiples of some fundamental pitch as is the case with a guitar string or even our square waves. To make these metallic sounds, we’re going to need to mess things up a little bit, and the logic function we’re introducing today to do it is the exclusive-or (XOR).

An XOR logic gate has two inputs and it outputs a high voltage when one, and only one, of its inputs is at the high voltage level. When both inputs are low or both inputs are high, the output of the XOR is low. How does this help us in our quest for non-harmonic content? It turns out that the XOR logic function is the digital version of a frequency mixer. (Radio freaks, take note!)

Ideal frequency mixers take two input frequencies and output the sum and difference of the two input frequencies. If you pipe in 155 Hz and 200 Hz, for example, you’ll get out the difference at 45 Hz and the sum at 355 Hz.

Because we’re using square waves and an XOR instead of an ideal mixer, we’ll also get other bizarre values like 2*155 – 200 = 110 Hz and 2*200 – 155 = 245 Hz, etc. All said, the point is that we get out a bunch of frequencies that aren’t evenly divisible by one another, and this can make for good metallic sounds. (And Dalek voices, for what it’s worth.)

## The 4070: Quad XOR

Which brings us to our logic chip du jour. The 4070 is another 14-pin wonder, just like the 40106 and the 4069UB and the power and ground pins are in the same places. Since an XOR gate is a three-pin deal, with two inputs and one output, only four XORs fit on the 14-pin chip instead of six inverters.

By now, you’re entirely used to the 4000-series logic chips, so there’s not much more to say. This is a great chip to add sonic mayhem very easily to your projects.

## Frequency Modulation with XOR: More Cowbell!

Let’s make some metallic noise. The first step is to mix two oscillators together. Whip up two variable-frequency oscillators on the 40106 as we’ve done now each time, and have a listen to each individually. Now connect each output to the inputs of one gate of an XOR in the 4070. As promised, the resulting waveform is a lot more complex than either of the two inputs.

Now tune them around against each other and listen to all the strange frequency components created as the sums and differences slide in and out. Cool, no? Here’s a bonus video that you can skip, but that demonstrates what’s going on with the frequency mixing.

## Two-diode VCA

After a couple of minutes playing around, you’ll start to realize that this sounds nothing like a cowbell. We’ll need to shape the volume of the sound in time to get anywhere, and this means another step in the direction of “traditional” synthesizers. We’ll build up a ghetto voltage-controlled amplifier (VCA) and drive it with the world’s simplest envelope generator.

An active VCA takes its input signal and either amplifies or attenuates it depending on the control voltage (CV) applied on another input. When the control voltage is high, more of the sound gets through, and when the CV is zero, the output is ideally silent. Building a general-purpose VCA is a bit out of scope for our needs, so let’s just cobble something together with a few diodes.

This circuit works by cheating, and works best with digital logic signals like what we’ve got. When the input from the XOR is low, diode D1 conducts in its forward direction and all of the control voltage signal is “eaten up”, sunk into the output of the XOR chip.

Conversely, when the XOR is high, diode D1 is reverse-biased and blocks the CV, leaving it nowhere to go except through diode D2 and out to our amplifier. The resistor needs to be large enough that the XOR can sink all of its current, but otherwise the size is non-critical.

Notice what’s happened here. The voltage at the output is no longer the GND to VCC of our logic circuit, but instead ranges only from GND to the control voltage (minus a diode drop). So if we want to make a quieter version of the XOR input, we just lower the control voltage. It’s a simple voltage controlled attenuator. Now we just need to create a voltage signal that’s got something like the amplitude contour of a cowbell.

Remember how we converted square waves into trigger pulses by adding a series capacitor? The resulting voltage had this steep rise and exponential trail-off.

If we add in another capacitor, we can lengthen out the decay. And then while we’re at it, we can add in a potentiometer to control the rate of that decay.

Capacitor C1 converts the square wave into a pulse and charges up C2 very quickly, applying the positive voltage to the input of our VCA. The charge on C2 drains out through the variable decay potentiometer.

This simple circuit actually works well, but has one shortcoming. For long decay times, as illustrated above, the decay gets cut off when the control square wave goes low. If you only want short percussive hits, the simple circuit is enough. If you’d also like longer decays, you’ll need to add a couple diodes to chop off the negative part of the control voltage spikes.

Now that only periodic positive spikes are getting though to our decay capacitor, we have a nice variable-rate exponential decay voltage envelope. Here’s how it looks on the scope (with some extra capacitance slowing down the attack — it might have been connected to the laptop soundcard). You can clearly see the control-voltage envelope chopped up by the diode action and the XOR’s output.

Putting the XOR frequency-modulated sounds through the two-diode VCA that’s driven by our quick and dirty envelope generator gets us a percussive metal sound.  But it it cowbell?  We still have to tune the oscillators up.

The classic, love-it-or-hate-it, cowbell sound of the 1980’s has to be the Roland TR-808. And if you look through the 808 service manual (PDF download) you’ll see that it uses two square waves from a 40106 chip simply mixed together. We’re improving on that by XORing, but we can still learn a bit from Roland. In particular, they tune their oscillators to 540 Hz and 800 Hz.

Because we’re XORing two oscillators together, our peaks come in at the sum and difference frequencies. This means that we’ve got to solve X + Y = 800 and X – Y = 540. Grab pencil and paper, or just believe me that you’ll want to tune up the individual square wave oscillators to 130 and 670 Hz respectively. At least, to get something like that classic cheesy cowbell sound.

## Amplification Aside

We’ve been trying to stick to the use of purely CMOS logic chips here, but this session we broke down and used a transistor. The reason is that the audio input on our laptop insists on a bipolar, centered audio signal. In contrast, the output of our “VCA” sits mainly at zero volts with very short peaks up around one volt. The input capacitor in the laptop is charging up and blocking the VCA’s diode output. Boo!

Indeed, we can’t use our old tricks with the 4069UB as an amplifier here either. The 4069UB works great for signals that are centered around the mid-rail voltage, but distorts near either GND or VCC. Unfortunately, we’d like our quiet drum sounds to taper off to zero volts rather than the mid-rail, so we’ll have to use something else to buffer our audio with.

The solution is to buffer the output with something suited to this unipolar signal, and the simplest solution is a plain-vanilla NPN transistor hooked up as a common-emitter amplifier common-collector amplifier. This configuration is a very useful analog buffer circuit; it puts out almost the same voltage as the input, but draws directly from the VCC rail and will certainly handle any sound card’s input capacitor. We used a 2N3904, but a 2N2222 or BC548 or whatever will work just fine.

## Cymbals

Cymbals and similar metallic percussion instruments were pretty tricky to synthesize in the early days of drum machines. Until the LinnDrum introduced sampled cymbals, most just used a shaped burst of white noise. The aforementioned TR-808 used six 40106 oscillators linearly mixed together to approximate white noise. Again, we’ll improve on that by running it all through XORs with the result being somewhere between many oscillators and pure noise depending on how you set the oscillators up.

The inspiration for this circuit is the fantastic Synbal project (schematic in PDF) from “Electronics & Music Maker” magazine in 1983. It’s a much more complicated affair than what we’re doing here, but if you look at the left-hand side of the schematic, that’s the core. (If you’re copying the Synbal’s fixed frequencies for the oscillators, note that he uses 0.01 uF capacitors and we use 0.1 uF caps. Divide the feedback resistors by ten accordingly.)

The trick to the cymbal circuit is making a lot of oscillators. We’ll hook up six of them, finally fully fill our 40106 chip. Then combine any pair in an XOR, take the output of that XOR and combine it with another oscillator. You’ve now got a complex oscillator that’s used up three 40106 oscillators and two XOR gates. Repeat this with the remaining oscillators and XOR gates and you’re nearly done. Connect the final two XOR outs through resistors to the output.

As with the cowbell circuit, this circuit can be made to sound “realistic” by picking the different component frequencies just right and tweaking the decay. We think that it makes a pretty decent hi-hat sound with a couple of the oscillators pitched high (1 kHz and up). On the other hand, if you’re into noise music you can skip the VCA altogether and tune the oscillators to similar, low frequencies. You get a vaguely metallic, almost rhythmic machine drone. Not to be missed.

## Extensions

We’ve snuck it in under the guise of making a cowbell sound, but the quick-and-dirty VCA here is also useful for modulating most of the synth voices we made in the first few sessions. We went for a percussive attack by using a capacitor to couple the driving square wave to the VCA, but there’s no reason not to use a variable resistor in its place to charge up the capacitor more slowly. If you do this, note that the attack and decay potentiometers will interact, so it’s a little quirky, but what do you want for two diodes anyway? Also note that any other way you can think of delivering an interesting voltage to the junction of the two diodes is fair game.

The XOR-as-frequency-mixer technique is pretty great, but you can also get a lot of mileage by using the XOR as a logic chip. Combining different divided-down clock outputs (from a 4040, say) with XORs makes interesting sub-patterns, for instance. And we’ll get more use out of the XORs in two sessions when they’re coupled with shift registers.

## Next Session

We’ve got a whole lot of possibilities by now. We’ve got some good, and some freaky, percussion voices. We’ve got a bunch of synthesizer sounds, and if you recall back to the 4051, we’ve got a good way to modulate them by switching different resistors in and out. It’s time to start integrating some of this stuff.

If you’re following along, your homework is to build up permanent (or at least quasi-permanent) versions of a couple of these circuits, and to get your hands on at least two 4017 decade counter chips. Because next week we’ll be making drum patterns and introducing yet one more way to make music.

# Hacklet #8: The Animals

This week on the Hacklet we’re looking at Hackaday.io projects that are all about animals! Hackers and makers are well-known animal lovers, in fact many a hacker can be found with a pet curled up at their feet, or on their keyboard!

[Brian’s] cat Roger loves drinking from the bathtub faucet. Unfortunately Roger hasn’t learned how to operate the faucet himself, so it gets left on quite a bit. To keep Roger happy while saving water, [Brian] created the Snooty Cat Waterer. Cat’s still don’t have thumbs, so [Brian] turned to capacitive sensing in the form of a Microchip MTCH10 capacitive proximity sensor chip. Coupled with a home etched PC board, the waterer can detect a cat at 3 inches. A valve and water feed teed off the toilet provide the flow. The project is moving along well, though Roger has been slow to warm up to this new water source.

[Jsc] has the opposite problem. His cat has decided that bathtubs are the perfect litter boxes. [Jsc] is taking aim at this little problem with his Cat Dissuader. After a servo controlled squirt bottle proved too anemic for his needs, [Jsc] turned to the Super Soaker Hydrostorm. These electric water guns can be had for as little as \$16 on sale. [JSC] didn’t want to permanently modify the gun, so he 3D printed a switchable battery pack.The replacement pack is actually powered by a simple wall wart. Power to the gun is controlled by an Arduino, which senses his cat with a passive infrared sensor. Since the dissuader was installed, [Jsc’s] cat has been a model citizen!

Cat’s don’t get all the love though, plenty of engineers and hackers have dogs around the house. [Colin] loves his dog, but he and his family were forgetting to feed it. He created Feed the Dog to help the household keep its four-legged member from going hungry. [Colin] tried a microcontroller, but eventually settled on implementing the circuit with old-fashioned 4000 series CMOS logic chips. He used a 4060 (14-stage ripple counter w/ internal oscillator) as an 8 hour timer, and 4013 dual flip-flop. Operation of Feed the Dog is as simple as wagging your tail. Once the dog is feed, the human presses a button. A green “Just fed” LED will glow for 30 minutes, then go dark. After about 6 hours, a red LED turns on. After 8 hours, the red LED starts blinking, letting everyone know that it’s time to feed the dog.

[Steve] has outdoor pets. Chooks to be exact, or chickens for the non Australians out there. He loves watching his birds, especially Darth Vader, who is practicing to become a rooster. To keep track of the birds, he’s created What the Chook?, a sensor suite for the hen-house. He’s using a GCDuiNode with a number of sensors. Temperature, humidity, even a methane detector for when the bedding needs to be replaced. An OV528 JPEG camera allows [Steve] to get pictures of his flock. The entire project connects via WiFi. Steve hopes to power it from a couple of AA batteries. [Steve] also entered What the Chook? in The Hackaday Prize. If he wins, this will be the first case of flightless birds sending a human to space!

Hey – Did you know that Hackaday is building a Hackerspace in Pasadena California? We’re rounding up the local community while our space is being built out. Join us at a Happy Hour Show & Tell Meetup Event hosted by our own [Jasmine Brackett] August 18th! It’s an informal show and tell, so you don’t have to bring a hack to attend. If you’re local to Pasadena, come on down and say hello!