Wednesday, December 26, 2018

4051 CMOS Voltage Controlled Switch--bringing together ATTINY, VBB Simulator, Zener Clamping in a Single Post


I had 4 days off from work for the holidays so it seemed a good time to close out a few topics and actually build something.  Wait? Build something?  Yes....



topics that need closure:

First, ATTINY Atmel chips in DIY audio.  When (small) size matters, these chips are amazing, and amazingly inexpensive. Think of an Arduino the size of an 8 pin op amp!  Yeh!

I have already written about these in this post: introduction, setting them up, how to program them, etc.; as well as this one: Pros and Cons. Why use ATTINY vs. something else? And finally here: interrupts (useful for all Arduino audio DIY perhaps, examples are for ATTINY85).

Second: The Virtual BreadBoard (VBB) simulator.  I simulate a CMOS/CV controllable switch toward the bottom of this post.  With the simulation successfully running, I made it into a working DIY synthesizer module with minimal breadboarding.

The 4051 switch

Third: Clamping. What is the best way to get CV or audio into an Arduino Analog in without potentially frying things? (Answer--getting ahead--using zeners is the best thing I could find)

And of course, the inevitable "probably useless to anyone but me" build notes along with photos.  And: the obligatory sound sample of the module: here. The vid below captures a small part of the demo as it was being recorded. You've been warned!



OK let's get started:

In case you don't already know the 4051 CMOS MUX chip is super useful to Audio DIY.  Think of a solid state switch that can select 8 sources and, using 4 logic lines, output the chosen source to a single common pin. Or send the one source to 8 outputs--same idea.

Along with the 4051's cousins, the 4052 and 4053, these are staples of the audio world; you can see the 4051 at work here and here for instance.

But I had never built anything w/ any of them and it was time for that to change.

Along the way there were a few challenges to overcome:

Buffering.You probably won't need to buffer Arduino logic to a CMOS chip, but that's not what we are exclusively doing here. We are connecting analog CV and audio to a CMOS chips' input pins, and it's a fair bet you can't plug a 4051 I/O pin directly into a 120V AC socket and have the IO pin live to tell the tale. To solve this (and no, please don't really plug your 4051 to your house mains, bad idea!) I used a 1N5231 zener diode and op amp.  More in a bit.

Powering the 4051. Notably the 4051 has 3 power inputs--VSS, VDD, and VEE, for negative supply volts, positive, and ground, respectively.  So you can switch bipolar AC audio through the chip if you set up its power and logic levels correctly.  I don't use bipolar switching for this module but it's good to know you can.

From messing on the bench, the signals sent to VSS, VDD, and VEE determine the amount of voltage needed to equal "HIGH" in digital logic-land. To make this module easier to build I used 0 to 5V to power the ATTINY; logic and power for the 4051 is 0 to 5V as well. I have adequate level shifting and bias voltage offset circuits (previous posts here and here) elsewhere on my modular so this works for me.

But: if I used a 2u panel I would have gone for +5 for VSS, ground for VEE, and -12 for VDD. That allows a 10V bipolar analog signal to get through the switch relatively unscathed. The switch action is still controlled by 5V logic. This is an interesting configuration for future 4051 builds. More at this forum post.

About the module: Design goals are to allow 4 CV inputs switched to 1 output using a pot or 0-5V CV; LED's to display which channel is selected, and use of an Atmel ATTINY vs. all the other Arduinos, comparators, op amps, relays, etc., that could do this. Cram all this behind a 1U FracRak panel. And of course, recycle code from Virtual Breadboard--see the post on VBB here, that's what started all of this.

Block diagram for this module....

I used a new experimenter PCB for this project. I call the board an "ATTINYfactory" which you can see on my website. The idea is one size fits all for whatever ATTINY DIY audio project I conjure up. Some of them anyway.

If you go to the site, feel free to download the eagle files, send em off to get fabbed etc. if you want, or do whatever. If you use it or modify it please comment below and I'll post whatever you come up with. Or, p-m me: cslammy on the electromusic forum. I can probably send you a leftover if I have one.

For a change, there were no major mistakes on the REV1 board, however, the V+ on the bottom right, directly below the ATTINY chip, is wired for +5V not +15.  Should have labeled that better.....

The "ATTINYFACTORY" board, Rev1.  Rev2 already in the works....

Buffering and zeners. Atmel MCUs will accept decent amounts of current+voltage at their input pins, and can source decent amounts of current at output, but you run the risk of blowing up the pin if you get too crazy. After some discussion with fellow synth nerds and a bit of time on the bench, using a zener diode to clamp the output of an op amp is easy, and can limit current fed into the Atmel MCU to something safe.

The basic idea: slap a 5V zener between ground and the side of a resistor facing away from an op amp:


R6 has to be chosen to not exceed the wattage (V x Current) of the upstream signal, but for most of what we do a standard 1/4 watt 100K is fine. If you don't have 100K, use something bigger--470K or 1M will work. 

The op amp has very high impedance at its non inverting, virtual ground input, so it doesn't care what is upstream really. For this project I used 1N5231's for 5V.  Seems to have worked.

Good news is that 1N5231s are small and were easy to kludge into a quad non inverting buffer.

I just noticed the extra crappy soldering job for IN1, but hey, it works....

I tried other clamps--such as a rail to rail op amps, but they didn't work as well. The easy solution wins out again.

OK time to build--first I drilled out a PCBWAY fabbed "alubase" front panel to accept the LEDs. I used Eagle to create the LED legend at 200mils apart, printed out the legend, and taped it to the front panel.


The input jack and LEDs on the right were fabricated on perfboard.Yes I still use perf.....rarely.
Next, whamboozle it with a drill press:



And check to make sure the ATTINY circuit originally crafted on VBB works in the real world when modified for ATTINY...yes, it does!  If you want to review the code it's on GITHUB.


Let's gather up all the daughter boards....I have lots of op amp mini boards already fabbed.




Now it's a matter of assembling all of it, documentation for the entire module is here. Lots of wiring as usual. Easier than creating "skiff" PCBs and then just having to kludge the crap out of it? Because pots go the wrong way? The LEDS light up backwards?  Maybe. Maybe not. A couple of times I wondered "will this ever get done?" because of all the 22 gauge hook up wire used.  I have to cut down on the amount of wire I use in these one-off prototypes!


Test fitting some of the boards.  Will it fit into 1U?
Almost done.  The 4x op amp board fits best in back.  The TL081 output board is soldered to the side.


Christmas Day in the evening I tested the finished module. CMOS.  CMOS run.

One LED didn't work (bad solder to the perf) and I had the CV buffer board VSS wired incorrectly so the A1 pin on the ATTINY wasn't seeing anything at all. Easy to trace the signal with a scope and fix both of these--took only a few minutes. Now it all works.  I just have to Lazertran this and another one is in the bag. This one was fun!

Ready to test....


Update: about the sound clip for this module. I thought the 4051 switch would be good primarily for slowly switching CV's for VCO and VCF modulation but it turns out it's powerful being switched at audio speeds, turning this odd module into a very strange waveform generator (VSWG). 

Everything on the sound clip was created this way. Switch input sources are various combinations of pink noise, mad bees, aconitum noise, a 40106 oscillator,  LFO outputs, ground (so, no sound, causing a gap in the waveform produced), and various DC voltages (so odd square waves are produced) as well as the usual sine waves, ramp, pulse, and triangle. 

To generate the 0 to 5V CV to switch between inputs I used a audio frequency random gate, aconitum noise, a 13700 TH-VCO (ramp worked best; sweeping the 4051 switch CV with audio slowing to low frequency proved interesting), and CV controlled variable tempo square wave LFO's at near audio frequency. The trick seemed to be to make the 4051 sweep through its four inputs hundreds to thousands of times a second vs. just some boring CV at input swept every few seconds. Sometimes in a linear fashion; sometimes randomly.  The 4051 can work fast!  Makes me wonder what an 8 channel version of this would sound like?

As usual no DAW tricks to get this sounding the way it sounds here, this is pretty all my analog DIY synthesizer.  I did roll off some low and high EQ and add a touch of reverb here and there to keep speakers from frying. 

OK that's it for another round.  Not sure what is up next, always so much to do, so little time....I could see doing a 16 channel version of this with CV in (ramp to make it go 1 to 16, sawtooth for 16 to 1? Random for random?and clock in as well; use it as a easy sequencer? As an audio oscillator if you pushed the 4051 to switch really fast? Not sure.

The Christmas holiday is over with New Years coming up. A few more days off work. There was a time when every new years I was out playing, but no longer. Maybe that's for the best, now I can enjoy the holiday at home with my new family. Until next time, Rudolph: it's the holiday--don't breathe the fumes for a change.


No comments:

Post a Comment

EFM/KORG770 VCF--BUILD: yes, SOUND: no

Ahoy!  This time, I wanted to refine the quick prototyping idea discussed midway through this previous post : Minimal breadboarding--I hate ...