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.