Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC analog input protection

Status
Not open for further replies.

Peet19

Member
Hello!
Should the analog input of the PIC be protected with a resistor? In this case, does the current flow into the PIN?
I want to measure the voltage at the center terminal of a potentiometer.
Thanks in advance for your help!
 
If the pot is supplied by the PIC power, it can be directly connected, as nothing can make it exceed the 0V to V+ range.

For anything that could cause the input voltage to exceed the PIC supply, use a series resistor and a diode (preferably a schottky diode) from the input to power - or to both power and ground - to limit the voltage.

If the input is high impedance, eg. 10K or higher, add a 0.1uF cap from input to PIC 0V / ground, and a protection diode from input to power.

You may get better accuracy by adding the can even with lower impedance inputs.
 
Note, there's also a current limit per port (maybe) and a current limit for the whole chip (120mA/85mA). However, unusually for this chip, max current is 50mA per pin.

Each port pin already had protection diodes to Gnd and Vcc so only requirement is not to exceed their max current (20mA). So if reading a 9V signal then use a >200Ω resistor in series (assumed Vcc=5V). However, it's better to use a higher impedance resistive divider.

Adding an input capacitor to ground improves the ADC acquisition time. Think of it as a storage battery (100nF = 100,000pF) that can quickly charge the tiny battery (15pF capacitor) inside.

Mike.
 
One more quick question. The maximum output current is 50 mA?
That's the from the "Absolute maximum" table - the level where you may expect failure, not what's allowed in normal operation.

See the output voltage vs current graphs on page 406; "sink" current is shown up to 25mA, with a loss of about 0.5V, but source current is only around 5 - 7mA to get a similar voltage drop.

Also note the absolute max current through VDD and VSS, and the total power dissipation. Keep everything reasonably well under those, of you want the device to last.



There was a long discussion on here a while back about preventing any current to pins in analog mode, as it can cause problems if not latch-up in the device.

One of the most basic things is that as the ADCs need a low impedance drive (unlike using eg. a 1M in series to a digital pin to limit current), an overvoltage from the ADC divider may provide enough current through the protection diode to VDD, if no outputs are sourcing current & loading the supply more, to increase the device supply voltage and overvoltage it.

That can also happen via external protection diodes if the voltage divider is not calculated correctly. The diodes are last-resort and power fail protection rather than a normal operating part of the device.

Good design means always keep voltages within the correct limits.


Each port pin already had protection diodes to Gnd and Vcc so only requirement is not to exceed their max current (20mA). So if reading a 9V signal then use a >200Ω resistor in series (assumed Vcc=5V). However, it's better to use a higher impedance resistive divider.

"Real Bad Idea" ™

The whole device may be taking 5mA or less when running on the internal oscillator.
That means your 9V via 200 Ohms, dropping 1V across the resistor at 5mA, could massively overvoltage the device.

That's an example of why you should never rely on the input diodes as part of the overall circuit function.
 
As I said, much better to use a high impedance resistive divider.

No, because the ADC needs a low impedance source to charge/discharge the sample and hold capacitor - something like a maximum of 2.2K? (depending on the exact device). High impedance divider followed by a buffer is the better way, with the buffer opamp fed from the same supply as the PIC.
 
Why would we be discussing protection diodes if we were feeding the ADC?
I was talking about IF 9V was present.

Mike.
Perhaps you should read the title and content of the thread :D

PIC analog input protection​


The inputs have protection diodes regardless of analogue or not, and it's MUCH more likely that an analogue input could exceed the supply rails.
 
It is a good idea to take the manufacturer's word as gospel, otherwise, you have nobody to blame if things go poorly,

The datasheet, in section 20.7, says:

Since the analog input pins share their
connection with a digital input, they have reverse
biased ESD protection diodes to VDD and VSS. The
analog input, therefore, must be between VSS and VDD.
If the input voltage deviates from this range by more
than 0.6V in either direction, one of the diodes is
forward biased and a latch-up may occur.


In other words, echoing what rjenkinsgb wrote in post #8: Good design means always keep voltages within the correct limits. Use an external means of limiting input voltage on this chip. rjenkinsgb also wrote: That's an example of why you should never rely on the input diodes as part of the overall circuit function.

So forget the maximum I/O current and just keep the voltage within limits as discussed above.

There are microcontrollers out there that specify the maximum current that can be injected into the protection diodes without causing SCR latchup, but this is not one of them.
 
Hello!
Should the analog input of the PIC be protected with a resistor? In this case, does the current flow into the PIN?
I want to measure the voltage at the center terminal of a potentiometer.
As long as the voltage at the input can never exceed the PIC supply range, you do not need a limiting resistor.

If it could possibly exceed supply or go below ground, use external schottky protection diodes.

Outputs and their current restrictions are a totally different thing to inputs.
 
My opinion is that it would be better if you mentioned what aspect of the circuit you are asking for comments on and then at least called out the major components in that part of the circuit, and (one would hope) explain what you expect them to do. Some of us are pretty good at doping out how circuits work, but a description never hurt either.

For example: if Q1 were rotated so it's collector "looked" more positive than the emitter (was higher on the page than the emitter) and the signal flowed from left to right it would be recognized and an inverter driving a speaker much more quickly. Is that the kind of feedback you are looking for? I doubt it.
 
Forget the coin cells! They will not run a circuit such as that with LEDs etc., as they cannot stand significant current without the voltage dropping off extremely quickly.

They can run a low current circuit such as an MCU with no display or a non-backlit LCD for extreme periods, as long as the MCU is only woken when required - but not anything that needs tens of milliamps.

Other than that, a full description of the intended function and what may be connected to the port connectors is really needed.

See the graph below for the effects of low vs high load current:

Discharge%20capacity%20Panasonic%20CR2032.png
 
My further question would be, can the PIC drive the LED display like this?

Yes, check my tutorial hardware page:


That uses common anode rather than common cathode, but is essentially the same - and as it only has two digits (I happened to have a dual-LED at hand) it only needs a single I/O to switch between them.

Have you considered using plugs and sockets rather than building everything on one board? - as I did in my tutorials, it makes it much more versatile, and if you can use only 8 pins (as in my LED example above) you can plug it in any full 8 bit port.

This is a board I've been using recently for 28 pin devices - J1 is external power in, PL1 allows selection of 3.3V or 5V regulators. PL3 and PL4 are specifically for the connection of FTDI serial converters (no power required - so only 3 pin), and J2 and J3 for SPI devices etc. that need three I/O plus power. I double up the ten pin sockets because I use one for Molex (as per my original tutorial boards) and the other for XH-2.5mm connectors, the smaller ones are XH-2.5mm as well.

28Pin_DevBoard.png
 
Thanks for everyone.
I took the resistor off the analog input. It is connected directly to the middle terminal of the potentiometer. I think the supply voltage for this PIC is 3.3 V. I want to put a 130 ohm resistor on the digital outputs. That's good?
Maximum 25mA, if I count correctly.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top