Showing posts with label Digikey. Show all posts
Showing posts with label Digikey. Show all posts

Friday, October 16, 2015

Surface Mount DigiPot with an Arduino Uno

For an upcoming modification to my Korg Polysix, I need to be able to attenuate an analog signal in response to the user's inputs.  This is a perfect task for a a digital potentiometer.  If I can, I'd like to control the digipot from an Arduino, because an Arduino is so easy to program.  There are two challenges with this plan, however.  First, my preferred digipot is only available as a surface mount device.  Second, I'm worried that the Arduino is too slow to drive the digipot quickly.  Well, I do like challenges, so let's just dive in and see where we can get!

Driving my digipot with an Arduino Uno.  How fast can it go?


Choosing my Digipot:  There are many digital potentiometers on the market.  For use inside my Polysix, I might need to put digipot in a place where it would need to control voltages ranging from -5V to +5V.  Most digipots cannot handle this kind of bipolar voltage range (most are just 0-5V).  Of the choices that I saw on Digikey for bipolar digipots, I chose to buy an Analog Devices AD5260 (link).  As you can see it in the picture below, it's a tiny little surface-mount device.  Scary!  (actually, don't be scared...it'll be fine)

Analog Devices AD5260 Digital Potentiometer.  Surface Mount!  Tiny!

Surface-Mount Adapter Board:  Because I'm usually just hacking stuff together, and because through-hole components are much easier to hack with, I don't have nearly zero experience soldering surface-mount components.  If I made my own circuit boards, I would certainly use more surface mount components because they save so much space.  For this hack, however, I need flexibility to plug, unplug, and reconfigure my circuit.  Therefore, I'm going to put my surface mount device onto a an adapter board that gives it legs like a through-hole component.  My digipot is a TSSOP-14 package, so I bought a TSSOP-14 adapter board from Adafruit.  It comes as a pack of 6, so I have spares in case I make a mistake.  :)

Mounting my surface-mount digipot to a through-hole adapter board.

Soldering Surface Mount ICs:  How do I actually do the soldering?  I talked with a co-worker who is extremely experienced in this area and he gave me a pile of good advice.  Two parts of that advice were: (1) use very fine (thin) solder and (2) use lots of flux.  Unfortunately, by the time I got around to soldering (days later), I had forgotten these two important details.  As a result, using my too-thick solder and using no extra flux, I created many solder bridges between the tiny legs of this tiny IC.  This is not what you want to do.  But, through perseverance, and through extensive use of solder wick to remove excess solder, I finally got the IC soldered no shorts or bridges.

Magnification (Or, How to Look Cool):  One piece of my colleague's advice that I did follow was to use some magnification.  He let me borrow an "OptiVisor" (see picture below).  It doesn't feel like it provides much magnification, but it is enough to give a clear view.  And, I'm learning that if you can *see* it, you can solder it.  The OptiVisor provides that.  They're also quite fashionable (that would be sarcasm).  

It definitely helps to use some magnification so that you can see what you're soldering.

Add Legs for Breadboarding:  The Adafruit adapter board has through-holes on either side for attaching pin headers.  As you can see below, I used a regular piece of 0.1" break-away pin header.  I broke off two seven-pin segments, temporarily placed them into my solderless breadboard, put the digipot board on top, and soldered the pins on.  This through-hole stuff is easy!

Soldering the pins to the breakout board so that I can easily prototype with the digipot.
Using a solderless breadboard keeps everything aligned while you solder.

Deciding How to Connect:  With the digipot's adapter board finished, I had to figure out how to wire up the device.  Below is a picture from the digipot's datasheet with my own labels added to show what I would connect to each pin.  All connections were going to my Arduino.  As you can see, there are a bunch of 5V and Gnd connections.  Commands are sent via the SPI bus, so there are also the three SPI connections (theSDO line is not needed as there is no communication needed back to the Arduino).  Finally, for the pot's input, I'll simply apply 5V, which means that my output will be a DC voltage that is scaled between 0-5V.

Signals to use for testing the digipot with an Arduino, which uses 5V logic.

Wiring to the Arduino:  The wiring plan shown above requires 12 connections.  Since I am usually prone to error when doing my wiring, I choose to draw up a little picture to fully illustrate to myself how I should use my solderless breadboard to make all of these connections.  This extra "design" effort really made the wiring process much easier.  It also made the wiring process more reliable.  Once I got the Arduino software working, the wiring of the hardware worked on the first try!

Wiring an Arduino Uno to the my digipot via a solderless breadboard.

Writing the Arduino Software:  To change the value of the digipot, I had to write some Arduino code to send commands to the digipot via the Arduino's SPI pins.  I started with the Arduino's built-in example called "DigitalPotControl".  While that code is simple and easy to understand, I wasn't sure if it runs the SPI bus as the fastest possible setting.  Speed is critical for using this in my Polysix, so this detail was worth a little effort.  After Googling around, I found the correct Arduino commands to control the SPI bus speed and I wrote my test program (SPI mode is zero!).  My program is shared on my GitHub here.

Initial Test:  My test program steps through a range of the digipot values.  It stops at each step for three seconds, which gives me enough time to confirm that its output is correct.  Because the input of my digipot is connected to +5V, my output will be between 0V and 5V.  For the picture below, the digipot was at a value of 125 (out of 255), which resulted in an output voltage being 2.47V.  Given that I expected (125/255*5) = 2.45V, I got pretty decent agreement.  In other words, it works!

First test.  It successfully created a voltage half-way between 0-5V. 

Testing for Speed:  Now for the full speed test.  I commented out the delay() and println() commands and restarted the system.  If used in my Polysix, there will only be 15-20 microseconds (usec) to change value of the digipot.  This means that the Arduino + digipot must support an update rate of 50-67 kHz, which seems pretty fast for an Arduino.  To see how fast my system was actually running, I connected the output of the digipot to an oscilloscope.  The full setup is shown at the picture at the top of this post.  A screenshot from the oscilloscope is shown below.

The Uno is changing the digipot as fast as it can.  It takes 16 usec per step, which results in an update rate of 62.5 kHz.

How Fast is It?  The picture above shows that the digipot is only being updated every 16 usec, which means it has an update rate of 62.5 kHz.  This is within my 50-67 kHz requirement.  So that's good, right?  Well, no, not exactly.  I am a little uncomfortable with the fact that there is no margin.

The Need for Margin:  In achieving this 62.5 kHz result, the Arduino is doing nothing but updating the value of the pot over and over endlessly.  That is all that the Arduino is doing.  In my envisioned hack for Polysix, however, my Arduino would need to do a few other tasks, as well.  For example, the Arduino will need to listen to its Serial port so that it can receive commands as to what values to use for the pot.  If the Arduino is running flat-out just to maintain a high update rate, it probably wouldn't have enough spare cycles to service the serial port.  That would be unacceptable.  So, while it is exciting that I got the system to operate this well, I think that the that the Arduino Uno isn't quite fast enough.  I need to try something else

Trying a Teensy:  My next step is to try a faster Arduino.  Or, an even better plan would be to step up to the fastest Arduino-like board that I know: Teensy 3.  But I think that'll have to wait until my next post.

Update:  My results with the Teensy are here.  The Teensy is *really* fast!

Sunday, May 5, 2013

Killing and Reviving my Polysix (Replacing a Dead IC)

So far, I've been pretty successfull with hacking aftertouch, portamento, and detuning into my Korg Polysix .  My next big goal is the addition of velocity sensitivity, which requires me to better understand the VCF control circuitry on KLM-366.  Well, in probing the clock signals for the VCF multiplexing, I killed my Polysix!  This is the story of how I brought her back to the land of the living.

Probing IC12 on KLM-366.  I think that I've found the problem.
How Did I Kill It?  This all started when I was probing around the part of the KLM-366 board that processes the VCF EG signal for each voice.  Specifically, I was exploring the time-division multiplexing of the VCF EG through IC24 and IC23 .  This multiplexing is all kept in sync via clock signals "A", "B", "C", and "INH" that are generated from IC11 and IC12 (schematic below).  In probing IC12, I accidentally shorted one of the pins on IC12 (likely pin 11), which apparently killed it.  As you can see in the pictures above, the "B" signal is clearly bad (it is supposed to be a square wave pulse).


How Do I Fix It?  Replacing IC12 seemed like the only reasonable answer.  The chip itself is really cheap (68 cents).  The hardest part in replacing the IC is disassembling the synth so that I can get good access to the circuit board.  I don't like taking it apart because it gives me too many opportunities to loose screws and to re-connect connectors in the wrong place and stupid stuff like that.  But, in this case, I think that it needs to be done.

Shopping List:  The only part that I really needed was a replacement 14024 chip.  Like usual, I got it from Digikey.  The specific part that I bought was MC14024BCPGOS-ND.  I chose this part because (I think) it is the only through-hole version of the 14024 that they sell.  At 68 cents, I bought 2, just in case I damaged one during my installation.  Also, following the advice from The Old Crow, I decided to install an IC socket at IC12 in order to ease any future replacement of this chip. There are tons of choices for sockets.  Never buy the cheapest ones.  I liked the look of A32869-ND.  Even though it was only 78 cents, it seemed to be one of the higher end models.  Cool.

Removing the Dead IC.  The replacement process starts by removing the dead chip.  Some helpful folks at my workplace suggested that removing an IC is best done by first snipping off each of its legs so that the body of the IC just falls free of the PCB.  Then, as long as you snipped the legs high enough away from the board, there's plenty of leg left to grab with your pliers so that you can apply a little heat and lift each leg out one-by-one.  Pretty easy.

Snip Each Leg of the IC
All Legs Are Snipped, The Body is Loose, and the Legs are Still in the PCB.
Removing Each Leg from the PCB.
Removing the Old Solder:  Even after removing the IC's legs, there was lots of old solder that is plugging the holes in the PCB.  In order to get the new IC socket into all those holes, it's usually best to remove that old solder.  There are a few ways that you can do this -- solder wick and a solder pump being the two most common.  Clearing plugged through-holes is a perfect task for a solder pump.  With a solder pump, you first apply your soldering iron to the hole until the solder melts.  Then, you quickly put the spring-loaded solder pump over the hole and, while the solder is still melted, you hit the release button.  BANG!  The pump pops open and (hopefully) sucks out the liquid solder.  Because I'm new to this, I usually had to try 3-4 times before I got the solder out.  As you can see below, the holes looked fairly clear when I was done.

Using a solder pump to suck out the solder from the holes.
The holes are now fairly clean and ready for the new IC (or socket).
Installing the IC Socket:  At this point, I was able to insert my new IC socket into the holes in the PCB (see below).  It fit pretty nicely.  Now I just needed to solder it in.  Unfortunately, one really needs access to the bottom of the PCB to do this, which means the synth needs to be partly disassembled.  So, I removed the keybed, I removed the rail holding down the PCBs, and I unscrewed all the screws holding down the PCB.  I then removed a few (but not all!) of the multi-pin connectors so that I could tip up the PCB and get access to the bottom (see pic below...the power drill is holding the PCB upright).   Once I was able to access the bottom of the PCB, I was soldered the legs of the IC socket to the PCB.  We're cooking right along now!  Smell the solder!

Inserting the IC Socket.  It fits!
Getting access to the bottom of the PCB.
Soldering the legs of the IC Socket.  Heat the site and THEN apply the solder.
Finishing Up:  Once the socket was soldered in, I layed the PCB back down and I inserted the replacement 14024 IC into the new socket (see pic below).  I then re-attached all the connectors that I had undone, I double checked that I re-connected everything correctly, and I turned on the power.  With the oscilloscope, I checked the "A", "B", and "C" clock signals being generated by the new 14024 (see pic below).  Everything seems to work!

The replacement 14024 IC is nestled into its new home on my KLM-366.
After Replacing IC12, the clock signals all look good.
Oh, The Joy:  With the circuit looking like it's working again, I re-attached the keybed, closed the lid, and fired her up.  Here's my little jam of joy...the playing is crappy, but it's so good to hear her voice again.


Next Step: Tipping over the capacitors so that the keybed fits properly

Monday, December 31, 2012

Add Sample-and-Hold to Korg Mono/Poly

After my success with fixing the dead keys on my Korg Mono/Poly, I decided to try some of mods that are out there on the Internet.  One that seemed within my grasp was to, once again, follow the Old Crow and add a Sample-and-Hold circuit to the Mono/Poly.  What's the sound of a sample-and-hold circuit?  Well, this video shows how to setup the sample-and-hold on my modded Mono/Poly to get a great bubbly filter effect:



If you're interested in adding this to your own synth, I'd start with Old Crow's description here.  For my build, I used the same schematic as Old Crow, except I chose to hardwire it into MG1, instead of making it switchable between MG1 and MG2.  So, my modified schematic is shown below.


In terms of buying the parts, I went to Digikey, which is the standard place where professionals go to buy their electrical parts.  They've got nearly everything that you could ever want, but unless you know what you want with an engineer's precision, you can get easily flooded by all the choices.  If you've never bought from Digikey, I wrote a post to help guide you through the process.

For this build, let's talk about how to buy a few of the parts in the schematic...
  • The LF398 is the sample-and-hold chip itself.  I don't remember which one I bought, but try this one: Digikey LF398N/NOPB-ND.
  • The ferrite beads are a bit unusual to see in a hobbyist design.  I'm not sure how to pick the right ferrites for the filtering/decoupling task here, but Digikey M8697-ND is probably good enough.
  • You'll need a switch for "SW2".  Any single-pole double-throw (SPDT) switch will work fine.  Try Digikey 360-1801-ND
  • Finally, you'll see a bunch of caps in the schematic labeled "104".  This means that they are 10 * 10^4 pF, which is 100,000 pF, which is 0.1 uF.  These are commonly ceramic caps.  A decent choice might be Digikey BC2665CT-ND.
So, after getting all my parts, I wired it up on a piece of protoboard and then wired it into the synth (using a terminal strip to allow me to easily remove it for debugging).  Unsurprisingly, it didn't work.  This is a common occurrence with my tangled rats-nest electronics.  So, I spent some time poking around and finding lots of errors in my build.  Eventually, it worked!

Below are some pics of it in my Mono/Poly:

Elements of the S-H mod in my Mono/Poly.  Circuit board, Terminal Strip, and Switch.

Close-up View of my Assembled Circuit.  Ugly!

The red wire is how I chose to connect to the KLM-353 board for getting MG1.

Here's how I wired in the shielded cable to VR17 to get the noise source.

I'm not showing how I wired it into the mod wheel.  I've got additional modifications in this part of my synth, so the pictures would have been more confusing than helpful.  Sorry.

Once I got the circuit working, I was able to apply the sample-and-hold effect to anything that the mod wheel can affect.  On the Mono/Poly, that means the filter cutoff, the pitch of all the oscillators, or the pitch of just oscillator 1.  The most useful sounds come when applying the S-H to the filter cutoff.  The video at the top of this post shows that effect.  In my opinion, it's a great drone that can act as a fantastic bed for moody improvisation.  Enjoy!



Buying Parts and Using Digikey


Before I dive into my circuit modifications, I'd like to talk about how to buy parts.  As a non-professional electronics person, it can be hard to know what specific items to buy.  I mean, if someone says that you need a 10K resistor, where do you get such a thing?

Well, it's great if you can find what you need at hobbyist places like Sparkfun or Adafruit.  They really limit the choices to just the core essentials.  Having limited choices sounds like a bad thing, but it really is a blessing.  They have done all the work of sifting through the thousands of choices available and have narrowed it down to just the few choices that will likely fit what the hobbyist needs.  If you can find the part that you need at one of these places, it'll probably be the right one for you and you should buy it.

If they don't have what you need, you can go to a place like Jameco.  They've got more choices, which can be daunting, but they show a lot of pictures, so you can often shop by the pictures.

If you still can't find what you want, it's time to put on your big-boy pants and step up to "real" stores like Mouser and Digikey.  They're the places that professionals go to buy their electrical parts.  Their stores are ridiculously deep.  They're scary places to go at first, if you don't know what you want with an engineer's precision.  But, with a little practice, they get more comfortable, and then the whole world of electronics is open to you.

Let's go through an example of shopping at Digikey.  Nearly any time that you work with integrated circuits (aka "ICs" or "chips"), you'll have to use 0.1 uF capacitors to provide filtering ("decoupling") of high frequency transients on the power input line.  On most designs (even hobbyiest designs) 0.1 uF caps are everywhere.  Let's say you need to buy some.  In this case, they're so common that Sparkfun does carry them, so you should just buy them there.

Buying a 0.1 uF Cap at Sparkfun


But shopping at Sparkfun is not the point of this exercise.  The point is to try Digikey.  So go to Digikey and search for "capacitor".  You get 275,000 options.  Umm.  OK.  Now what?

Shopping for Capacitors at Digikey.  Lots of choices!

Well, for caps, you need to know what type (composition) of capacitor you want.  How do you know that?  Well, sometimes the schematic tells you ("electrolytic" or "polypropylene").  But, usually, it won't say.  What you need to know is that, for a given cap size, or for a given application, everyone seems to use the same type of cap.  It's tradition.  If you search around the web enough for people using a cap in a similar way as you, you'll be able to find out what everyone uses.

For synth hacking, most caps will be ceramic caps because they're small and cheap.  The biggest exception is for high capacitance caps (1 uF and bigger).  These caps are almost always electrolytic caps.

Returning to our example case of finding a 0.1uF cap for use around ICs, everyone seems to use "cheap" caps, which definitely means "ceramic" caps.  So, on the Digikey page, click on "Ceramic Capacitors".  This gets you down to 126,000 choices.  Note that the webpage has changed...

Digikey's page for filtering through all the choices for "Ceramic Capacitor"


This new page is giving you all sorts of filtering options.  Now's when we really start cooking:

  1. First, click on the checkbox for "In Stock".  Now we've got only 41,000 choices.
  2. Under "Capacitance", scroll down and select "0.1uF".  2,000 choices.
  3. Under "Voltage - Rated", use Ctrl-click to select "25V", "35V", and "50V".  944 choices.
  4. Under "Mounting Type", choose "Through Hole".  159 choices.

At this point, you've narrowed it down to a few pages worth of choices.  If the part you needed was a little less generic than simply a "0.1 uF capacitor", you'd probably only have a handful of choices now, instead of 159 choices.  So, you'd look at the pictures, maybe look at a datasheet or two, and then just pick one and go.

In the case of these caps, you probably want to down-select a little more.  Look under "Tolerance".  We probably don't want to pay for the best caps (smallest tolerance) and we never want the worst (biggest tolerance), so select "10%" and "20%".  That got us down to 128 choices.

Looking down through the first page of choices, the pictures all look like parts that I could work with.  Any of these would probably be fine.  Because I'm likely to be hand-soldering on a crappy proto-board, I think that I prefer the look of the caps with the long leads.  So, I'd probably buy some of Digikey Part BC2665CT-ND.  They're 37 cents individually.

Hopefully, a decent choice for a 0.1 uF capacitor from Digikey.

For cheap general-purpose components like caps, you should always buy more than you need right now.  I always buy extras.  That way, I might not need to order more when I go to my next project.  Having the parts on hand means that you can dive right in when the inspiration strikes and not have to wait for the shipping.  It's so much more fun when you can dive right in.

For something super general-purpose like 0.1 uF caps (or 10K resistors), I might buy 10 or more.  For these caps, you'll see that the price drops to 25 cents each when you buy 10.  Or, if you're really bold, you could buy 100 for only 10 cents each!  I'm not that bold....I'd probably just buy 10.

So, that's how one buys parts.  It's a very important skill to have when you're going to be hacking synths.  Anyone have any sites that they really like to use for parts?