Or How Not to Let the magic Smoke Out
Previously I've written about myI could say it's to help kids / beginners protect themselves from basic mistakes, but even after practicing Engineering for nearly 20 years I have learn that Murphy still bites, so it's also a lesson in self preservation :)
Testing
Defining The Problem
The Raspberry-Pi is a great little device (as most of the world knows) and I have all the best intentions of making my own MAME box with one. To do this, I plan on hooking up input buttons via the GPIO header, and possibly add some blinkenlights.But a quick look at the schematics and you can see that the GPIO header is a break out header only. The pins on the header are connected directly to the pins on the Raspberry Pi GPU. Should you short circuit, over volt, reverse bias or generally screw up your connection to any of the pins, you will probably blow that port, or even worse kill you Pi outright.
Not nice.
And that's just the IO pins. The header also breaks out the 5V and 3V3 rails on the raspberry pi - again directly without protection and if you mis-wire these you will also learn from this costly mistake...
My Solution
Similar to the Adafruit Pi-Cobbler, I've designed a board that will let you connect your Raspberry-Pi GPIO to a breadboard. If you've been following my blog, you'd see I've laid a fair but of ground work to get to this point:
- Looking at Protection Circuit ideas
- Making my own Solder Paste stencils
- Ordering PCBs and separating them
Well, I finally got around to assembling my boards for a test. I did this at home (so no access to the reflow oven at work) and as I was sleepy / rushing it I also managed to load all my diodes the wrong way around.
So after fixing that, and bumping my board, I'd smudged my solder paste *a lot* but trusting in solder mask, I grabbed my eBay Atten 858D hot air tool and took a shot at reflowing. You can see the result below.
Well bugger me, it worked! One diode ended up angled but this was soon fixed using a conventional soldering iron. Easy.
I'll go into details of testing below, but first some pics of my test setup.
Mounted on Breadboard
I added standard 0.100" pins to the board, and installed it into my breadboard.
Test Pins
To make testing easier, rather than installing the shrouded header, I've loaded some test pins:
- Black = Ground
- Red = 5V
- Yellow = 3V3
- White = a GPIO pin
Beats the heck out of probing around with multimeter probes.
The renders below show what I'm trying for with my final product - you can see the protection circuits are on the bottom side of the PCB - however their profile is low enough to clear the breadboard when installed.
The renders below show what I'm trying for with my final product - you can see the protection circuits are on the bottom side of the PCB - however their profile is low enough to clear the breadboard when installed.
Top Side
Bottom Side
Mounted
IO Protection
This was the simple part of the design. To protect the IO pins I took two approaches:
- Add Series Impeadance
- Add Voltage Clamps
Sounds fancy, but it's simply using tow common parts - resistors and zener diodes.
Rather than recap the theory I detailed in my previous post (scroll down to Zener Diode) I've got my design data to share, followed by real world test results.
DESIGN
For my design I chose to limit current in / out of the GPIO pins to 10mA, ad as the Raspbery-Pi is a 3V3 device you can easily calculate the required resistance using ohms law.
R = V / I, = 3V3 / 10mA = 3.3 / 0.01 = 330 ohms
For the Zener I chose this device, from the NXP BZX384 series, mostly for their size (SOD323 A.K.A. bloody small) and power rating (300mW).
The power rating lets you work out how much current your diode can sink, using P=VI i.e.
0.3W = 3.3V * I, I = 0.3 / 3.3 = 90mA
This effectively sets the upper operating voltage that the zener will protect your circuit from before it gives up and dies. If you apply 5V to an input you get the following setup:
Current is still limited by the resistor, which has (5V - 3V3) across it, for just 5mA. The zener then sinks this current.
(I'm ignoring any that the Raspberry-Pi sinks - this is okay as it's a high impedance device and draws very little current, and the 'error' introduced by this adds to my worse case scenario - my device will perform better than I expect.)
So the power dissipated in the zener is 17mW and the resistor dissipates almost 9mW.
I've calculated the power dissipated in each component of the circuit for a range of voltages which can be found here (see the tab labelled Zener Clamp (Theory)).
Note that the resistor exceeds it's power rating at 10V input, and the zener exceeds it's power rating when over 30V is applied to the input, so the zener isn't the weak link here.
TEST
Okay - that's the design, and the best way to check your design is to test it. Real work testing doesn't make decimal point errors...
To start testing I'd borrowed a bench PSU. Damn handy to have, I'll need to buy / hack one up as a permanent addition to my work bench.
To start testing I'd borrowed a bench PSU. Damn handy to have, I'll need to buy / hack one up as a permanent addition to my work bench.
PSU
The current meter, although useful, doesn't have the precision required for the task.
Meters
So I hooked up my cheap and nasty, uncalibrated meters, which are good enough for me. The small meter is used to monitor current, the larger volts out. Volts in are set / measured by the PSU.
Set Up
Up Close
I've recorded my practical measurements in the Google spreadsheet under the tab labelled Zener Clamp (Practical).
What's interesting to note is that as the input voltage increases, the Zener voltage also increases, and thus the voltage dropped across the resistor is less than theoretical. If you look at the values for 12V in, theoretically the resistor needs to dissipate 230mW, but practically it dissipates 200mW.
But what is interesting to note is that during testing I well and truly pushed the resistor above it's rated power. I managed to get over 10 times it's rated power with a 30V input, but that test was destructive. So how does the resistor cope with the over power stress? Well, the PCB heatsinks the resistor and if you can get the heat out you can push it harder.
If you were planning on constantly running a resistor at twice it's rated power, you will get a short working life out of it. However for this instance, I'd be happy as rating the clamp for protecting a GPIO pin for up to 15V.
What's interesting to note is that as the input voltage increases, the Zener voltage also increases, and thus the voltage dropped across the resistor is less than theoretical. If you look at the values for 12V in, theoretically the resistor needs to dissipate 230mW, but practically it dissipates 200mW.
But what is interesting to note is that during testing I well and truly pushed the resistor above it's rated power. I managed to get over 10 times it's rated power with a 30V input, but that test was destructive. So how does the resistor cope with the over power stress? Well, the PCB heatsinks the resistor and if you can get the heat out you can push it harder.
If you were planning on constantly running a resistor at twice it's rated power, you will get a short working life out of it. However for this instance, I'd be happy as rating the clamp for protecting a GPIO pin for up to 15V.
TTL LEVELS
If you take a look at the figure above, for the practical circuit, Vout is less than Vin. So when you inject a 'logic high' (3.3V) the clamp is allowing only a bit over 2.8V into the Raspberry Pi input. Is this a bad thing?
From this great page from NXP you get the picture below:
This compares all the voltage / logic levels for a whole range of TTL logic families. Looking at the 3V CMOS column, you can see that any voltage over 2.0V is defined as a logic HIGH so losing the half a volt in the clamp as described above is okay. When being driven by digital logic, you won't have to worry about compatibility - but if you were inputting an analogue value into the Raspbery Pi port (it won't do a D2A conversion but can be used as a trigger) you will need to take this loss into account.
Rail Protection
Okay, the GPIO was the easy bit. The tricky bit is protecting the power rails on the Raspberry-Pi.
Just like the IO pins, the power rails can be damaged by short circuits, over volts and reverse bias. You cannot use a clamp circuit as used on the IO pins, as a resistor will limit power you can deliver. But you can replace the resistor with a polyswitch, and just like the GPIO the practical results here vary from the theoretical. I'll cover how I tackled this in my next entry.
That's really cool. Would be great to be able to buy a ready piece of this stuff.
ReplyDelete...because I think I just burnt some GPIOs on my RPi... shit.
Hi Ludzinc,
ReplyDeletecould you provide a PCB design in Eagle, please?
This is very cool indeed, do you have the schematic anywhere? Thank you!
ReplyDelete