GPIO protection circuit for oscillating input voltage

FunkyAP
Posts: 3
Joined: Fri Apr 08, 2016 10:29 am

GPIO protection circuit for oscillating input voltage

Hello,

I have a signal that I would like to monitor with pi and I'm not sure what is the best way to do this. The signal is pwm and its frequency is 100 Hz and the high value is oscillating between 10 - 20 VDC, so I would need to limit this high value to max. 3.3 VDC. I'm not sure how much amperage I can draw from the signal so it doesn't disturb it.

It is quite simple to do with a voltage divider and get the amperage quite low, but it's not the best solution for protecting the pi.
I did some calculating and I could do it with a 1.2k resistor and a 2V7 zener but when the signal is at 20 VDC it draws quite alot of amperage from it.

I also found Tage's solution for quite similar problem in and older post:
https://www.raspberrypi.org/forums/view ... hp?t=42938

This solution seems to be the best option so far although may be a little bit of an overkill.
Any ideas how I should approach this problem?

Brandon92
Posts: 882
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: GPIO protection circuit for oscillating input voltage

The easiest and safest way of monitoring if a voltage is present. Is to use a optocoupler. For example see this application note.

aBUGSworstnightmare
Posts: 2063
Joined: Tue Jun 30, 2015 1:35 pm

Re: GPIO protection circuit for oscillating input voltage

As said alreday, that's what octocouplers should be used for. There will be no risk off damaging the PI as there is no connection between 'outside Signal' and Pi's GPIO.

davef
Posts: 64
Joined: Wed Feb 20, 2013 8:39 pm
Location: Christchurch, NZ

Re: GPIO protection circuit for oscillating input voltage

Making sure that 3V3 is the maximum voltage applied to the GPIO.

I understand that for isolation reasons an optocoupler is a better approach, ie especially circuits connected to mains power. But for DC and with common grounding in an installation are not voltage dividers or level shifters more appropriate?

Brandon92
Posts: 882
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: GPIO protection circuit for oscillating input voltage

@davef

Well, it also depends where this PWM signal is used for. As a example, if this signal drives a inductive/ capacitive load. This could generate voltage spikes. That can possibly kill the Rpi.

And in the case you can't drive a led with your PWM signal. If it is for example a sense line. Then you can safely use a voltage devider. Or the other possibility is to use a digital isolator.

But, which one is the best? It depends where that signal is made and how

davef
Posts: 64
Joined: Wed Feb 20, 2013 8:39 pm
Location: Christchurch, NZ

Re: GPIO protection circuit for oscillating input voltage

@Brandon92

Spikes I can see could be a problem with a simple voltage divider. I have used https://www.bourns.com/docs/technical-d ... t_form.pdf in the past.

Brandon92
Posts: 882
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: GPIO protection circuit for oscillating input voltage

Hello,

A tvs diode is indeed a good component to get rid of the voltage spikes. And a aditonal rc filter can do also a lot but not everything.

lbdroidman
Posts: 13
Joined: Wed Oct 17, 2018 7:46 pm

Re: GPIO protection circuit for oscillating input voltage

You can do this with a single N-FET with a VGS max that is greater than the maximum voltage your signal carries, and a VGS threshold that is lower than the minimum "on" signal. For example, VN2222LL has a VGS max of 30V (>20V) and a VGS threshold of 2.5V (<10V).

Now its an N-FET, so you will set your "detection" GPIO as input-pullup. When the 10-20 volt signal is ON, it will activate the FET and cause the GPIO to be pulled low. In other words, the signal you will receive by the pi will be inverted with respect to the 10-20 volt input signal, which is perfectly fine since you can recognize this inversion in your software.

Now the nice thing about using the FET for this application, is that they don't draw a current at their GATE, so you don't need to muck around with resistors to limit the current running it -- just take your 10-20 volt input signal and connect it straight up to the GATE. And the nice thing about an N-channel FET is that it will pull your GPIO down to GND, so the only voltage you need to worry about at the pi GPIO is its own pull-up resistor (internal).

The only thing that this doesn't account for is whether you are accurate as far as 20V being the absolute maximum that your signal will carry. If it ever goes over 30V, then you could smoke the transistor, and if you smoke your transistor, I cannot promise that it won't harm the pi's GPIO.

Brandon92
Posts: 882
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: GPIO protection circuit for oscillating input voltage

I don't think it is a good thing to drive a mosfet without a gate resistor. Because this could damage the gate internal. For example if you apply a pulse (20v) with a high dv/dt, the current through the gate capacitor (Ciss) can be to high. And can kill the mosfet.
In this case there could also be a overshoot on the PWM signal and it could be more than the steady 20v. Or there are spikes on that signal. So, I would advice a gate resistor and also a gate source resistor. To ensure the mosfet can be turned off (when the signal is not present).

But as I told before, we don't know where tat PWM signal is coming from.