edyb
Posts: 31
Joined: Thu May 24, 2012 3:11 am

Protection circuitry

Thu Jul 05, 2012 10:22 pm

I just read the latest Blog entry on the site regarding creating a break-out board like a Gertboard and wanted to understand more about the Zener diode component and how exactly that is supposed to work.

From my understanding of the schematics, each GPIO from the RasPi gets connected through a serial resistor (330 ohm? or my units wrong?) to the breakout board GPIO socket. That way, whatever you plug into the breakout board GPIO socket has it's current limited, even if you short it to ground, because of the resistor.

So where do you plug the other lead for the component you plug into the breakout board? Just that just go to the GND connection of the RasPi? Is that basically where the other lead of every component eventually goes to complete the circuit?

Now regarding the Zener diode, it looks by the schematics that it is connected to the GPIO as well, just before the resistor it branches off and the other lead goes to the GND as well. So it is connected the reverse direction. So if your GPIO is "high" won't it put out 3.3v and isn't that the threshold voltage for tripping the Zener the other direction, causing it to ground and therefore it would bypass the circuit you are intending to send voltage to... like the resistor-LED combo?

And then how is it that it allows you to use it as a GPIO input? I still haven't figured out whether GPIO inputs are also considered "high" and "low" only or if you can actually read incremental voltages, and what the range of voltages are that it will accept and current supply, and I haven't seen any examples.

Any help understanding the protection circuit with Zener diodes, how it works for GPIO in/out and what a GPIO input would actually be reading would be greatly appreciated! Sorry for the noob questions here but I am new to circuit electronics! :D

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Protection circuitry

Thu Jul 05, 2012 10:35 pm

A reference to a circuit diagram would help.
Normally you know what the input voltage is and you just divide that down.
You rarely have spikes above your supply voltage. If you expect spikes, you could use a zener diodes
for protection against high voltages but they are not designed for that.
They are just too slow. You use specially design protection diodes.
If the input signals are slow a good (low inductance) capacitor is also very good for catching spikes
and is about a ten times cheaper.

edyb
Posts: 31
Joined: Thu May 24, 2012 3:11 am

Re: Protection circuitry

Thu Jul 05, 2012 10:49 pm

I read the blog a bit more closely, to try to understand it... Here is what it says, and I quote:
It uses a zener diode across the input. Basically this will prevent the input voltage from going any higher than 3V3 because at that voltage it breaks down and starts to conduct thus clamping the maximum voltage on the GPIO pin at 3V3. Also is a negative voltage is applied then it acts like a normal diode and conducts preventing more than -0.7V being applied to the pin. Voltages outside this range will damage the GPIO pins. The 330R resistor will limit the current flow through the zener, dropping the excess voltage between that applied and 3V3 across it. Thus the GPIO is protected when it is used as an input. However, it also has a role in protection when the GPIO pin is used as an output. By limiting the output current to a maximum of 10mA it will stop the GPIO pin from being overloaded. Also if the pin is being used as an input and a switch is connected between the input and ground, there is protection if the pin is accidentally made an output and the switch is grounded. This would normally be a fatal condition but this simple resistor prevents it from happening. This circuit also allows an LED to be connected directly to the board, but always remember to teach people that a resistor is needed in the circuit it just happens to be built in here. There is a down side to protection, there always is, and it is that you can’t get more than 10mA from the GPIO pin and any logic you drive will only be pulled down to zero through 330R. Fortunately most logic families nowadays can cope with this.
Here is the image on the blog:

Image

So my understanding now is that it is INPUT which it is trying to protect. If you apply an input voltage greater than 3.3V then it will immediately ground it, and the ground is protecting the GPIO pin? So if you apply say a 5V to the GPIO pin then it will pass through the Zener and ground itself. I think my misunderstanding still has to do with how exactly INPUTs are wired up to the RasPi.

I think I understand how OUTPUTS are wired up. Basically they get connected to GPIO pin and then other end to GND. So for an LED you would use a resistor and LED in series and then to GND. When you turn on GPIO pin then it goes high and shoots out 3.3v which passes through your resistor/LED and then to ground to complete circuit and light up LED.

However, I am not sure how you would construct the INPUT. Let's say it is just a simple on/off switch. So is the GPIO as an input simply detecting whether voltage is above some threshold or below? Or can it actually read the voltage like a voltmeter? If it is just high/low then I assume you have your switch connected to the 3.3v on one end, and the GPIO pin on the other? And then when you close the switch the 3.3v goes through to the GPIO pin and it reads it as "high" ? Otherwise it is getting 0v and reads it as a low? I guess in that case the Zener protects it by grounding the switch since it will flip directions and let current pass through to ground (in case you accidently connect to say 5v and your GPIO input can't handle the 5v).

Regarding the output, I am still confused about that. I am also wondering whether that resistor of 330 ohm was chosen for any particular reason, if it just happens to be to protect the GPIO by limiting current or is it because it is optimal for LED usage? Or would I still need another resistor to match up with the LED I plan on using?

User avatar
Mortimer
Posts: 925
Joined: Sun Jun 10, 2012 3:57 pm

Re: Protection circuitry

Thu Jul 05, 2012 11:20 pm

The zener won't ground an input of more than 3.3V, it simply limits the Voltage presented at the GPIO pin to 3.3V.

It might be easier to think of a zener as being a resistor which varies its resistance according to how much over 3.3V the input Voltage is. At anything from 0 to 3.3V its resistance is infinite, or at least so high it can be considered so. Above 3.3V its resistance will seem to vary, so that in combination with the fixed 330R resistor, it divides the input Voltage so only 3.3V is present at the junction between the zener and the resistor, and hence the GPIO input pin. It would only appear to be virtually a short circuit or Ground the input Voltage, when the input Voltage is very high.

So for example if we say we would consider the GPIO input grounded if the resistance to ground was 0.1R, this would equate to an input Voltage of over 10,000V. I think the resistor would vaporise before that happened!!
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

edyb
Posts: 31
Joined: Thu May 24, 2012 3:11 am

Re: Protection circuitry

Fri Jul 06, 2012 2:57 am

I had a look at the I-V curve for Zener diodes and I see that below the reverse voltage threshold of 3.3v the current increases like an avalanche. So the voltage can never get any more but current can increase, so I guess the resistor is there to stop it from going up to high.

My understanding is that in a way, the Zener diode converts excess voltage into current... So more voltage applied just turns into huge amounts of current.

As far as calculations are concerned, I found this site to be helpful:

http://www.electronics-radio.com/articl ... -diode.php

Based on the calculation on that page, I am trying to understand the limits of the protection circuit. The one posted in the blog used a 330 ohm resistor. Are we to assume it was designed to handle 5V input just in case somebody uses that? Then the drop across the resistor is 5-3.3v = 1.7v? Working backwards then since V=IR then I=1.7/330 is 5mA? So that is the maximum current through the resistor?

According to the calculation on the above link, which used 12V and assumed a lot of things, I am not sure how that translates to the RasPi situation, and what the typical values are for the components like current needed, limits on current, wattage, etc.

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Protection circuitry

Fri Jul 06, 2012 11:44 am

You should also check the response time.
The V/I curve is taken when slowly increasing the voltage.
For a rapid spike the zener may not be fast enough.
It is one of the the most difficult features to build into protection diodes.
They have to respond fast and in a very short time absorb a lot of energy.

Neil
Posts: 98
Joined: Thu Sep 29, 2011 7:10 am
Contact: Website

Re: Protection circuitry

Fri Jul 06, 2012 3:01 pm

The majority of protection diodes are zeners. Sometimes they also back-to-back.

Thermal devices, on the other hand, do have some time lag in them so are not so good at handling spikes.

Return to “HATs and other add-ons”