Page 1 of 1

Protecting PIC Digital Inputs

Posted: Fri Oct 21, 2011 6:42 pm
by Ron
Hi,

I want to protect the digital inputs on my 18F4620.

I am using a 1x3 Male header to connect my sensors.
Pin 1 is the PIC PIN (Digital Input and is pulled hi to Vdd)
Pin 2 is 12V
Pin 3 is GND

I want to be able to power sensors that run on 10vdc - 20vdc as well ad make my own sensors that run at 5vdc. I will put 78L05 on my sensor pcbs using the 12V. I also want to be able to connect either a dry contact (push button) to the input as well as an NPN based sensor.

I have found this circuit in a few places on the web. The values of the Resistors and capacitor has never been given and was hoping someone would offer some suggestions with an explanation as to why they selected those values.

As I understand it:

R1 is simply a pull up resistor (this is typically all I have used in the past).
R2 is used to limit the current to the MCU pin.
C1 is used to help with noise and to debounce a mechanical contact input device (push button, reed switch).

I have read on a few sites that R2 could be up to a few hundred ohms and on other sites it should be 10K - 15K ohms.
I would normally use 10K pull up resistors but have been told there would be issues if both R1 and R2 were 10K (have been told that R1 should be more like 100K ohms).

I am hoping someone could explain what reasonable values would be for R1, R2 and C1.

Once my PCB's arrive I will start out using the following values.

R1 = 100K
R2 = 10K
C1 = 1uF to 2.2uF (C1 and R2 creating time value for contact debounce).

Thank you,

Ron

Re: Protecting PIC Digital Inputs

Posted: Mon Oct 24, 2011 12:48 pm
by Benj
Hello,

I would be very careful about connecting voltages that are over the microcontroller's VDD voltage to an input pin.

Personally I would use a resistor and a zener diode to overcome this problem rather then just trying to use a pull up. Using a pull up there is chance of the 10 - 20V getting onto the VDD line and causing damage.

Also from experience unless you are sampling analogue voltages and need to ensure you are not getting aliased data I would also leave off the capacitor C1.

So for protection at VDD voltages I would simply use a series resistor around 200 - 300R to limit the current going into or out of the device pin.

Re: Protecting PIC Digital Inputs

Posted: Tue Nov 01, 2011 1:43 pm
by RobZeilinga
While it is not the cheapest solution, I prefer to always use Opto-Isolators such as the H11L1 (also includes a Schmitt Trigger) for any project where I am not generating the input.

Re: Protecting PIC Digital Inputs

Posted: Tue Dec 04, 2012 10:48 am
by ingobauer
caisses enregistreuses

About the 240V AC with series resistance, the 10Mohm resistor limits the current to about +/-17uA. I would only use this if the datasheet explicitly mentions this as a safe amount of current for the clamping diodes, usually the documented safe maximum is no current at all. I would also be worried about transients. And you obviously have to treat your MCU circuit and everything connected to it as mains with regards to safety, creepage and isolation. Optical or magnetical isolation seems like the easier solution to me.