Friday, October 17, 2014

PS3 Cooling Fan Part 2

The first step of any project is to figure out the top level layout.  I have added the arbitrary constraint that this design will not use a microcontroller or any other high level component.  Just want to do something more.... analog.  Previously we figured out the building blocks, and actually worked off of a mental layout that is pretty much shown below.
It's really quite basic, but shows each part in need of design.  I did add the Fan Driver as an afterthought because we will need a means of driver large current to the fan.  But this shouldn't be too complicated, probably just a MOSFET.  Actually, we might as well knock this part out first since it will be simple.
OK, so slightly more than just a MOSFET.  Barely.  A diode is placed in parallel with the fan to prevent a small catastrophic catastrophe.  Let's consider this simplified model:

The fan has been replaced by an inductor and our PWM source (V2) is 100Hz with a 50% duty cycle.  On the right I'm showing conceptual ON and OFF state circuits where our MOSFET goes between a very small and very large impedance.

Pushing current through an inductor is a lot like starting your bike from a stop while in a high gear.  If you apply some pretty stiff force you can actually accelerate pretty quickly though you will feel quite a bit of resistance from the bike.  And as you get up to speed you'll start to approach a steady velocity, and the bike will feel much easier to pedal.   The inductor behaves somewhat similarly.  When a voltage is applied, the current has to "accelerate" over time to a steady state.  The graph below shows an inductor being charged then discharged several times.
Unfortunately the bike analogy falls a little short because charging and discharging the inductor has the behavior.  You can coast on a bike to a stop, or apply brakes, but neither reflects the behavior of pedaling.  The important thing to grasp here is that current through an inductor can not change instantaneously, even though the voltage applied can (in an ideal world).  It's almost like the current has a momentum.

So what happens when a branch get stuck in your spokes?  You flip over the handle bars.  The bike has stored up energy while at speed, and when the wheel is suddenly stopped it is dissipated in the form of you flying through the air and landing on the pavement.  This is the same as the MOSFET turning off.  An open circuit is basically an infinite resistance, or in my little example above, a very large resistance.  Let's suppose the device is switched on, given our values we'd see 24A flow once the inductor is charged up (I = 12V / .5Ω).  Now the MOSFET is suddenly turned off.  We know that the current through the inductor won't change immediately, so what happens to voltage across the MOSFET?  Well, Ohm's law: V = 24A * 5MΩ.  That's 120 megavolts!  Where there's smoke, you're spending a buck on a new transistor.  My example is totally unrealistic for many reasons, but the concept is there.  The circuit above simulated with the an IRF510 and with the fan inductor having a series resistance of 10Ω yielded this result:
Sure enough, there are voltage spikes.  The green signal is our PWM signal that turns the MOSFET on and off; the blue is the Drain pin of the MOSFET.  And as predicted, when turned off there is a very large but brief voltage.

Back to the backwards diode.  Now when the MOSFET turns off, the current has somewhere to go.  It just cycles back through the motor until the stored up energy is depleted.  No more voltage spikes.
This is commonly known as a freewheeling diode or a flyback diode.  It is good practice to throw them on any inductive load being driven by a switched DC source, such as relay coils, solenoids, and DC motors in general.  That's enough for the Fan Driver circuit.  Next time we'll start to figure out how to control it.

Monday, October 13, 2014

Virtual Whammy Bar Part 5

At this point it might be easiest just to show you the full schematic and break it down.
And there we have it, nothing too crazy. And yes, I'm not showing bypass caps and such (well honestly, I still need to add them to the real thing, but I know they should be there). So let's get into the remaining parts.

The MIDI interface looks like a standard serial connection, but it's not quite. MIDI uses a current loop so our output has a send and return path for the signal (contacts 4 & 5). On the input side of whatever device we are controlling will be an optoisolator providing... well... isolation. If you visit MIDI.org Elec Spec you will see the complete electrical interface. You may wonder why I didn't use the two inverters they show on the spec and here is why: that circuit is dated 1985. I'm guessing that at the time there was concern about how much current an I/O pin could sink. Dunno, I was maybe two feet tall at the time. But given the resistors in the current loop as 220Ω each and a forward voltage drop across the optoisolator of about 1.3V we would have 5.6mA. For a short across contacts 4 & 5 there is still only 11.4mA. According to the PIC16F916 datasheet, any pin can sink up to 25mA so long as all the I/O combined do not sink a current in excess of 90mA. I think we're safe.

On the right hand side we have two buttons with a simple RC filter for debouncing. The filter the cutoff frequency just wants to be as low as possible while still being faster than the rate that the buttons are sampled. This should allow for quick transitions while smoothing out any noise. There are only two buttons because that is all I had at the time.


The ICSP header allows for programming and debugging the chip in circuit via a Microchip programming tool such as an ICD3 or PICkit3. Not much to say here, if you're interested just google it or head to Microchip's website.

Lastly we have the two 7 segment LED displays. Again, I only had two on hand, but that was enough. I used the entirety of Port B of the PIC16 as a single byte output to keep things simple. I didn't pay much attention to how they were wired to the microcontroller, so long as they were wired the same. Either way, I'd have to make a conversion table in software to display numbers or characters, so my table is just.... unique. Also, I switch between which display is being illuminated by means of the "Digit" signal. When "Digit" is high, the ONES display is active, and when "Digit" is low, it becomes the TENS display. All I do is switch back and forth between them around 100 times per second and they both appear constantly on. This is easily done by alternating every time I check the buttons or check the position sensor. You may notice that "Digit" only drives Q2, and that the base of Q1 is tied to Q2's collector. How does the TENS display work then?
If you look at the simplified circuit shown and make a few approximations this can be easily understood. We'll assume that SIGNAL is 5V, Q2 is off(ie, "Digit" is low), the voltage drop across each diode is the same, and that the current gain of Q1 is 100. Since no current flows into Q2, we can formulate the following equations (again based on approximations):

Vb = Vc
Va = 5-(Ir * R) = V(D2) + Vb = V(D1) + Vc
Ir = Ic + Ib
Ic = 100*Ib

Let's just consider the current formulas. Since Ic is 100 times larger than Ib (and that is the minimum spec'd gain of a 2n3904), very little current is diverted from illuminating the TENS segment to drive Q1. So if Ic is 1mA, Ib is only 10uA, which also explains why the ONES segment doesn't appear to illuminate. Kinda neat. Didn't even need to consider the rest of the equations. This was initially a breadboard mistake that I had to evaluate after the fact to determine why it worked. Of course the real operation varies slightly from the approximation. The voltage drop over D2 will likely be smaller than D1 since it won't be driven into saturation, subsequently making Vb larger than Vc. What does this change? Not enough to care about.

So that completes the hardware portion of things. Software is up next.

PS3 Cooling Fan Part 1

Back in college I bought myself a Playstation 3 which has gotten plenty of use.  While I play games less and less, it still gets plenty of on time for dvd's and blu-ray's, Netflix, Pandora, and whatnot.  Other than a failed optical drive while still under warranty, it hasn't had any problems.
Then recently, while watching a movie, the PS3 beeped and turned off, leaving a blinking power light.  Subsequent attempts to unplug it and power it back off yield the same result.  Well now what?  While the price of a new system isn't that bad with the release of a new generation of consoles, I still payed a lot for the system I have when I bought it.  Not to mention all accumulated files and progress stored on the drive which is not as easy to recover as one would expect.  Off to the internet!
After a little searching around I found a solution.  Apparently the CPU and/or the GPU can heat themselves up so much that they can weaken their solder joints.  I believe they're BGA packages, so you can't bust out the soldering iron.  Fortunately, YouTube has a solution:

Watch PS3 Red Light Fix on YouTube

The basic rundown is that you have to pull the system apart and get the "motherboard" for lack of a better word.  Then you take a heat gun and warm up the board then focus on the CPU and GPU chips with high heat.  This should reflow the solder on the BGA pins and fix any broken connections.  Then apply some good quality of thermal paste and reassemble.  While I can't verify that the causes I've suggested above are actually the problem, I can vouch for the solution.  It does work.  I've done it on more than one system..... even the same one twice.... which gets us to the project at hand.
While first using the system, I had a small desk fan blowing across the system to force a little more air over the heatsink for the PS3.  After awhile I got a little more confident in the fix and stopped using the fan.  So one night while watching Netflix I fell asleep, and woke up later..... only to have the flashing red light again... Well, time to pull it apart and reflow again.  What I need is a fan that turns on and off with the PS3, and while we're at it, speeds up when the system gets hotter.  And a circuit that will make this work.

The Project:

Alright, the desk fan is out.  It's too big and clunky, and yes it could probably just be turned on and off with the PS3 via a relay, but what fun is that?  Now on to what I have laying around.  How about a pair of 92mm case fans?  These Nidec Beta V's (TA350DC M35105) fans are rated up to 5,700 RPM and 1.8A.  I'm going to stress at this point that I have no experience driving fans like these.  Sure I've driven some basic DC motors by varying the voltage or using a PWM, but this required a little more thought.  A PWM drive is the starting point.
OK, the fans are taken care of, but what about a heat sensor?  Well I don't have any thermistors and couldn't buy any locally.  But I did recall from my engineering courses that semiconductor devices have a negative temperature coefficient.  Sure enough, after a little research, I found that a silicon diode drop will vary around -2mV per °C.  This means that if your diode drops 600mV at room temperature, when heated 10°C above ambient, it will only drop 580mV.  And this behavior is pretty linear across temperature and consistent from part to part.  And yes, resistors also have a positive temperature coefficient, but it never crossed my mind to use one.  The change in voltage will be dependent upon the applied voltage for one (the voltage will proportionally change the same regardless the applied voltage, but it's a matter of dealing with uV or mV for actual change in voltage; larger applied voltage = larger observable change).  Also, the temp coefficients can be pretty small with resistors, and I have no idea what they are for the ones I have.
Now we've got fans and a candidate for a temperature sensor, how are we gonna power our circuit and get it to turn off and on?  Well the PS3 is really just a computer packed to look like a gaming system.  It has to support various configurations and use some modular componentry such as the hard drive, optical drive, USB, wireless, Bluetooth, etc.  And like a PC, it has a dedicated power supply module that is similar to ATX supplies.  When the system is off there is 5V standby power to illuminate an LED and operate a soft switch circuit.  When the appropriate signal is applied to the power supply, it turns on the main 12V rail and the PS3 fires up.  All we have to do is tie into the 12V portion of the supply.
We have a pretty good start: fans, temperature sensor, drive mode (PWM), and power supply.  Time to design.

Saturday, September 27, 2014

Another ATX bench supply....

So for a long while I've wanted to make a bench power supply from an old ATX supply from an old computer.  As I don't have a lot of equipment on hand, I've had to resort to scavenging wall transformers or power bricks to do my projects.  I'm still using a 1A wall supply a teacher had us modify(just cut off the barrel plug and added banana plugs) in our introductory electronics course in college.  But while I can get a decent variety of voltages by hacking up a unused supply I have to keep a box of these around and most can only offer up to 1A or so.  And negative voltages?  Not without some work.
These limitations can be frustrating.  It's a hassle to rummage through the box of supplies to find the right voltage with enough juice.  Once I was trying to diagnose the cabin blower fan for a friend's car in the middle of a cold winter.  I removed the fan from under the dash and wanted to test it.  But when it's -10F and dark outside, you'd prefer not to stand outside and try wiring it up to the vehicle battery.  However, testing indoors is a little tough when you need a +12V supply that can provide, say 10 or 20 amps.  It would have been nice to have that ATX supply handy...  In the end I had to confirm the operation of the fan out in the cold.  Turned out the fan worked, but the contacts in the fuse panel had roasted themselves to the point of melting some of the plastic and were essentially open circuits.  A little dis-assembly and sanding of the contacts got things working again... so far.
Well back to the project at hand: the ATX bench supply.  Initially I did a search of the internet and found that many people have done just what I planned.  So I plodded on without reading their write-ups cause I wanted to do my own thing.  I grabbed a 250W unit out of an old Dell and got to it.
The first task: turn the ATX supply on.  This I had already accomplished while troubleshooting some motherboards for various people.  All it really took was a web search for the ATX power spec which provided this little diagram:

This pretty much tells us everything we need to know.  The main Molex plug that normally goes to the motherboard includes all the signals and voltages.  All the other wires going to plugs for various drives, fans, and whatnot aren't really necessary and can be removed altogether, which I did.  So turning this thing on.  You'll notice as signal called 'PS_ON#'.  When this signal is connected to ground our supply fires right up.  Design wise, the project is kinda done.  The rest is physically rigging the supply up to be practical.
You can see that I've added a couple LED's for indication.  There is always a low current standby 5V source when AC is plugged in (via 5VSB), which will be designated by the yellow LED.  When the outputs settle, the PWR_OK signal goes high, which I use to drive the red LED on.  I didn't find how much current the PWR_OK signal could source, so to play it safe I just drove a transistor with it.  Not much else to really say.
Unmodified power supply.


Wire bundle from power supply.  Most redundant wires were removed.

Terminal strip mounted, dry erase marks for switch and LED drilling.

Internal modified wiring with switch and LED board mounted.  Used a spare piece of proto board cut from another project, held in place using hot glue.

Power supply reassembled.  Future modification would be to drill a new hole to feed the wires up in order to clean things up.  Other than that, works just as intended.

Tuesday, August 12, 2014

Virtual Whammy Bar Part 4

I would like to quickly go over the power supply section. Though not shown on our basic layout, we have one, and it's a given that any project will need to consider how power will get to the circuit.
Didn't do anything special here, just a plain 7805 linear regulator. Almost straight off the datasheet. Again, used caps I had available. As an aside, my GND's aren't really grounds, but commons. The GND symbol is just really easy to grab in the schematic editor I'm using, and I figure we all understand functionally what is going on. But I didn't really want to talk about how this circuit is designed so much as I did the ramifications of the circuit.
Linear regulators are simply inefficient. In this setup using a 9V battery, 4V have to be dropped across the regulator in order to produce the 5V output (I am assuming an ideal battery for the sake of discussion). At the same time, the rest of the circuit for the project is going to need what current it needs. Knowing that Power = Volts x Amps, we can see that about 44% of the power delivered by the battery is dissipated across the regulator as heat for any given current draw. So 56% efficiency. Ouch. My initial design for the whole project only drew about 70mA, which I thought was pretty decent. But a quick search of the internet revealed that a typical 9V battery has around 565mAh (milli-amp hours) of life. My device would drain the battery in only 8 hours!
This is where switching regulators become really nice. Some are drop in replacements, and others require a few external components, but all are still simple enough to work with. And with efficiencies north of 90%, they are a very attractive option. Lets consider our 9V battery in terms of mWh instead of mAh. That means we have 5085mWh of life in the battery. Multiply by the 56% efficiency of the linear regulator and we have only 2848mWh remaining to power the circuit. The circuit itself draws 350mW. Again doing the math we see 8 hours of life. Let's consider a 91% efficiency switch regulator now. Only 9% of the power is lost regulating, leaving us with 4627mWh. Now the device can last 13 hours! Not great but still better.
At the end of the day what I really did was make the whole circuit more efficient. This was done through a combination of selecting better resistor values, and writing code to turn things on and off as needed to save on idle power draw. After several iterations of changes the current draw was reduced to <10mA. Now I could operate the device for at least 56 hours (again, ideally). I could take it a step further and add a switching regulator to eclipse 90 hours, but guess what? I don't have one of those lying around.....

Virtual Whammy Bar Part 3

Alright, which section to figure out first? How about the sensor? If that doesn't work, the rest of the project is a bit of a moot point. It would just be cart without the horse.... or some other idiom.
My initial plan was to use some kind of capacitive sensor that would simply be a metal plate mounted to the body of the guitar. As a matter of fact, the idea of a capacitive sensor was what started this whole project. I don't exactly recall what got me started on it, I just thought it was a cool idea in need of a application.
So one afternoon I soldered a lead to a small piece of copper clad board about 2" x 2", added a few components, hooked up the probe scopes and started waving my hand about. And I really didn't get far. Couldn't really detect any affects on transients without physically touching the pad. After a host of small modifications and trying different things I decided this needed a little more research. Perhaps I'll get around to giving the idea more serious time in the future. And I'm pretty sure there are IC's I can buy for this purpose with app notes.
With the not so successful capacitive test I let the project sit for a little while. Then one day at RadioShack looking for a relay for my car's power antenna I spied an IR LED and detector combo. The photodetector option was one I had considered, but I had convinced myself not to go down that road. But I decided to part with my $2 (which was way overpriced of course) and shoved them in a drawer at home.
Eventually I got around to playing with the photodetector(PH1) and it was a pretty simple design process. Now I really didn't know anything about using a photodetector as I had never used one before, so it was off to the internets to do a little research (also note that as a Radioshack part, there was little info about the part). Many designs I found admittedly I didn't fully understand at the time, but it became apparent how the device could be used. So the trick was to reverse bias it in series with a resistor(R16) and think of the detector as a sort of light controlled pot or light controlled BJT... or something. For the initial tests I slapped probably a 1K or 10K resistor on the breadboard and fed it to an op-amp buffer circuit using an MCP601 ( a part I had lying around). Oh wait, I still need an IR source.
Luckily, the packaging for the parts did include some maximum ratings. The emitter(D1) had a peak forward current rating of 150mA and a typical forward voltage drop of 1.3V. This we can work with using Ohm's Law:
Plugging in the numbers, assuming Vcc = 5V, we roughly get R17 = 25Ω. Well I have 100Ω handy. And besides, we don't need to be redlining the little guy. We'll have a forward current of only 37mA, but that'll be plenty. Now it is time to build and test.
Success! Not perfect operation, but I was able to observe a small voltage swing on the output as I moved my had closer and further from the diodes. I did try inserting an object in between the diode lenses which had no effect so long as they were pointing in roughly the same direction. And according to the packaging, that should be the case as the detector only has an angle of sensitivity of 20 degrees. So about that small voltage swing? Easy, just put a larger resistor in series with the detector. Since the photodetector is going to allow a current to flow, the voltage seen at the input of the op-amp is going to be that current multiplied by the resistor. Bigger resistor, bigger voltage. I did have to try a few values before settling on the 1MΩ you see in the schematic. Now I could detect my hand from about 1 to 10 inches away.
Up to now, I've been quiet about Q3 and the Zero setting pot(R1). That is because these guys came into play after the whole design was done and working. For the time being, I'm just going to tell you that Q3 was added to turn the LED on only when needed in order to save power.
The potentiometer on the other hand, was somewhat of a design necessity. I did this little project over the course of a few days, sometimes working in the afternoon, and sometimes in the evening. In the afternoon everything worked great, the detector output was stable and repeatable. In the evening though, I was getting fluttering values when nothing was present above the detector. As it turned out, the lamp on the hutch above my desk was emitting enough IR and/or near IR light to introduce a sort of noise. If you look at a datasheet for a photodetector, you will see they have a peak sensitivity to a certain wavelength of light. However, they will have diminishing sensitivity to the surrounding wavelengths on either side of the peak. My lamp, producing both heat and light, was definitely polluting my results.
A feature of any ADC is that you can set the lower and upper voltage references to scale the conversion. In this case using the 10-bit ADC on the the PIC16F916, I had 1024 bits of resolution. But those 1024 bits could mean 0-5V, or 1-2V, or 2-5V, all depending on the reference voltages used by the ADC. I simply used the 5V supply as the upper reference, then added the pot to set the lower reference. So when my lamp is producing, say 600mV of noise, I set my pot for 700mV at the wiper. Now the ADC won't output a number above 0 until I move hand close enough to overcome the 700mV threshold. In practice you need not know the actual voltages, just trim until the detector appears to stop detecting (it doesn't, but the microcontroller acts as such).
Of course, by setting the zero point to a higher voltage, we've reduced our physical detection range. In engineering we make compromises. But realistically, we don't need that sort of range to simulate a whammy bar anyway. To further improve the performance of the detector, we can use some kind of fixture for the two diodes which will improve the directionality of incoming light and also includes a tinted lens filter to reduce the incoming power from wavelengths surrounding the one of interest.
Well that was quite a lengthy discussion for the hand detection circuit, but now we can move on knowing the crux of the project works.

Tuesday, August 5, 2014

Virtual Whammy Bar Part 2

OK, now it's time to start figuring this thing out. The overall goal is to take some sort of hand motion, quantify it, and send an appropriate MIDI message to some digital effect unit.
First we'll need some sort of sensor. We can go ahead and assume it will produce some sort of analog output. Now we need some sort of analog-to-digital converter (ADC) and something to manipulate the result and do all the work. I picked out the PIC16F916 microcontroller for this purpose (because I have them on hand!). This 8-bit device has a built in 10-bit ADC that can sample more than fast enough for our purposes. It also has a built in UART which can be configured for MIDI output. Even better, it has a built in oscillator which will give us a 2MHz effective instruction clock, again plenty quick for this project. Our basic design is pretty simple:

This isn't the definitive design, we'll want to add a few bells and whistles such as buttons and a couple 7 segment displays to control the device operation on the fly. But to start, this will do.

Saturday, August 2, 2014

Virtual Whammy Bar Part 1


Project Abstract
So I already have an effect pedal that can do the trick, what's the problem? Well maybe I want to use my hand to control the whammy function for a more natural feel as opposed to my foot on a pedal. And again in my case, I would also like to keep the expression pedal available for functions like volume and wah. With modern music equipment we do have an option: MIDI. Both my GT-8 and the Digitech Whammy provide MIDI (Musical Instrument Digital Interface) inputs for external control over the effects.
MIDI is a simple serial protocol (think PS/2, I2C, anything using RS-232, etc) that has been around since the early 80's for the real-time communication of musical information. For instance, if you hit a middle C on a MIDI keyboard, it will send a message to a synthesizer to play a note (a "Note On" command), what note (middle C in this case), and how hard you hit the key (referred to as "Velocity"). The synthesizer in turn takes this info and creates audio output based on its current instrument patch, such as piano or strings. Releasing the note on the keyboard then sends a similar command, but with a "Note Off" command instead.

Command ByteData Byte 1Data Byte 2
100100000011110000111111
Note On CommandMidi Channel = 0Note = 0x3C = 60, Middle C on a pianoVelocity = 0x3F = 63, about half volume

Shown above is the actual MIDI message to play a middle C. You can see that the first byte contains a four bit command and a four bit channel assignment. Logically we can see that there are 16 possible commands and 16 possible channels. The channels represent devices in the MIDI chain. An example could be a situation where you have one or more synthesizers each capable of playing several instruments at a time. The first synth might have a guitar, bass, and keyboard assigned to channels 0, 1, and 2. Now you can add a drum machine to the chain which responds to messages on channel 10, and then a reverb unit on channel 12 and so on. Depending on the command, the data bytes will have different meanings. These data values can range from 0x0 to 0x7F (0 to 127 in decimal). I'm not going to thoroughly explain MIDI here, more information can be obtained from MIDI.org.
The goal of this project will be to turn hand motions into MIDI messages that an effect pedal will respond to.

My First Project!

For my first project, I will be sharing my "Virtual Whammy Bar" with you. This is actually a project that I've already done much of the work on, so this is more recap for myself. So I guess I'll begin with a little background:

Background
Many of you may already know what a whammy bar is, but for everyone else, a whammy bar(also called tremolo) is essentially a handle mounted on the bridge of a guitar that allows you to bend the pitch of all the strings simultaneously. It also is capable of bending the notes being played down in pitch, whereas with the typical bending of the strings with your hand can only bend the notes up. There are many different resulting sounds that can be produced from subtle tremolos to a "Dive Bomb". Go and listen to Hendrix or Steve Vai and you will probably hear some whammy bar use. But one thing to be noted is that many, perhaps most, guitars are not equipped with a whammy bar. There are a host of reasons not to build every guitar with one, but I will not go into them here; we'll just leave it at there being many objective and subjective (and believe me, everything guitars is subjective) trade-offs and compromises.
So what if you want take your Gibson Les Paul and achieve the unique sounds of a whammy bar? Well fortunately we have effect pedals. A quick search of www.guitargeek.com shows both Joe Satriani and Johnny Greenwood of Radiohead as having used the Digitech foot pedal in their rigs at some point. I personally own a Boss GT-8 which is a multi-fx board that includes a pitch bending feature that be controlled via an expression pedal. Both of these are controlled using your foot to adjust an expression pedal, which will lead us into the project at hand.

Whammy Bar YouTube Clip

Digitech Whammy YouTube Clip

Unfortunately I couldn't find clips comparing similar uses of the whammy effect, but I would note that the pedal lends itself to more extreme uses. I had a difficult time finding a clip where the performer did not go from full off to full on. Perhaps another impetus for my project......