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 impedance question

Status
Not open for further replies.
Hi Nigel,

PIC supply is 5V and voltage to measure is from a 3 cell LiPo battery, so the voltage is in the range 9-12.6V. The PIC just needs to know when the voltage is getting below 9.6V so the battery is not damaged by deep discharge.

Most Li-ion/Li-pol cells can have protection circuits built into the terminals to prevent deep discharge and over voltage unless you are using raw cells which can be dangerous. Another thread entirely.

https://www.tenergy.com/32002

With such a possible variation of input impedance of a PIC, I would as said use a buffer amp to provide the current to the sample & hold circuit and scale the buffer amp.
 
Measure the performance? Dunno, I just need it to work reliably :)

I'm using a batterypack made for RC hobby. I don't use any protection of the battery other than this low voltage measurement. I could add a 7A SMD fuse to prevent the battery from exploding if a short circuit happened, but it's only 180mAh so the explosion would probably just be a puff.
 
Last edited:
I don't use any protection of the battery other than this low voltage measurement.

So, a single programming bug can cause an explosion? Don't worry about the accuracy of the adc.. worry about the reliability of your code..
 
No, only a short circuit can cause the battery to overheat and "explode" and the short circuit should come from the device that the battery delivers power to (a car horn) or from me fiddling with the wires, which I don't do with the battery connected, and I don't do it after soldering all the connections to the PCB.
 
Hello there,


This topic comes up quite a bit, i'd say roughly once per year. The most accurate answer is that the PIC data sheet for the 12F675 (and possibly others) is not accurate. The problem stems from the fact that they quote "if you use 1/2 bit error" combined with "10k" as the input pin series resistor. There is no way you can meet the 1/2 bit accuracy requirement and still use 10k on any PIC analog input. Note that there is no such thing as accuracy vs timing here...if you have the time then you get the accuracy because if the timing doesnt meet your acquisition time then you lengthen your acquisition time or lower the resistor value. So there is no equation that is going to relate accuracy to acquisition time in this manner.

The real accuracy problem comes about because of the *leakage current* of the analog pin, not the timing. That's why many of the other data we read states "2.5k max". If you want to meet the 1/2 bit accuracy specification, then you must use 2.5k or less. Here's how it works out...

Every analog pin has a leakage spec associated with it, and that spec is plus or minus 1 microampere. So that leakage current is specified as a current source that is internal to the PIC chip and can not be changed. And that current source develops a voltage outside of the PIC package that appears across the series resistance usually quoted as being "Rs". Now it's simple to calculate that 1ua through 10k ohms gives us 10mv of error voltage, and that is regardless of power supply or reference voltage. However, the power supply or reference voltage plays a part anyway because the bit values are dependent on the reference voltage. If the reference voltage is as high as 5 volts, then the value for one bit is:
1 bit=5/1024

and we see this is approximately equal to 5 millivolts. So 1 bit is 5mv, and that makes 1/2 bit equal to 2.5mv. This starts to make a lot of sense all of a sudden :)

We now can calculate the maximum error. Since the error voltage is max 10mv and the bit value is 5mv, we see we have a possible error of 2 bits. So what does it take to meet the 1/2 bit error spec? Well, since 1/2 bit is 2.5mv and 1ua develops 2.5mv through a 2.5k resistor, we have our answer: 2.5k.

Of course not every application has to meet the 1/2 bit error requirement, but if yours does or you want it to anyway, then you must use 2.5k or lower. If you use 10k then you might see an error as high as 2 bits and it will vary with temperature. If that doesnt hurt then you're ok. I did one application using 25k and it works pretty well because it is used at room temperature and that doesnt vary that much.

So the choice is yours, but if you do want that maximum possible accuracy then you MUST use 2.5k. That's why they state that in some of the other documents.

There may be a chance that we can calibrate and stabilize the temperature, but i dont see any temperature data given in the data sheet for leakage current vs temperature. Maybe we can find that data somewhere.

Also note that if the reference voltage is less than 5v then you need an even lower value resistor than 2.5k. For a 3.3v reference voltage, we would need 2.5k*3.3/5=1.65k.
 
Last edited:
  • Like
Reactions: 3v0
Every analog pin has a leakage spec associated with it, and that spec is plus or minus 1 microampere.

Sorry Al, but I would disagree - it's mostly down to the time taken to charge the sample and hold - apart from that the source impedance can be considerably higher than the maximum specified.

Like I said previously to the OP, try the different value resistors, and compare the results.
 
Sorry Al, but I would disagree - it's mostly down to the time taken to charge the sample and hold - apart from that the source impedance can be considerably higher than the maximum specified.

Like I said previously to the OP, try the different value resistors, and compare the results.

Hello Nigel,

Well if you disagree then do a simulation where you have a 1ua current source in parallel with the resistor and external source to be measured. You'll quickly see that we gain or loose 10mv depending on the polarity of the leakage current. There's no way around this. And that is equal to two 'bits' not 1/2 bit.

Unless you are disagreeing with the plus or minus 1ua spec, which is clearly on the data sheet as the max leakage current.
 
The datasheet's "1uA max leakage" is a bit pessimistic, based on my experience.

I routinely use 100k, 220k, even 560k in ADC voltage dividers and the ADC measured result is never too far from what the calc says it should be. So, based on that I don't think I've ever seen a PIC input pin set to analogue input that draws 1uA, but I guess you could be right. I always calibrate the ADC by testing, and always use a decent sized cap (0.1uF or more) on ADC inputs used to measure DC voltages.
 
The datasheet's "1uA max leakage" is a bit pessimistic, based on my experience.

I routinely use 100k, 220k, even 560k in ADC voltage dividers and the ADC measured result is never too far from what the calc says it should be. So, based on that I don't think I've ever seen a PIC input pin set to analogue input that draws 1uA, but I guess you could be right. I always calibrate the ADC by testing, and always use a decent sized cap (0.1uF or more) on ADC inputs used to measure DC voltages.

Hello again guys,

I agree fully, when we go by the max we are looking at the device in the worst possible way. If it does what they say it could do then we will see this worst case possibility though, so to prepare for the worst we would want to make sure we cover all the bases. And this is where theory trumps experimentation unless we are willing to go to the extreme to test as well. As i stated in my other post(s), i myself used higher than 10k in at least one application and i got decent results, and that is a test by experimentation. However, my experimentation was limited to about 25 degree C ambient with maybe plus and minus 10 degree C deviation, whereas the data sheet has to cover the cases for the full range of temperature. And we usually see an increase in leakage current as the temperature rises. So if we go by the data sheet and want to cover the full temperature range and still get 1/2 bit accuracy, we must take that 1ua into account. But again this doesnt mean that every application actually needs this level of signal integrity.

To actually test this we'd need to select a random set of packages from various manufacturing lots and run the temperature up and down from the min to the max for each package. I assume that the manufacturer did this and that's why they spec plus or minus 1ua. They state 0.1ua min, but they do in fact state 1ua max and they dont state that just for the heck of it :)

What else would be interesting to test is if this leakage current changes with input voltage. For example, what is it at 4.9v input and what is it at 0.1v input. Do we see any error in output codes with a very high resistance? I've never tried that but it would be interesting if anyone wants to try it. Of course we'd have to repeat with 1k input series resistance too.

So actually testing for this parameter can be pretty hard to do if we really want a good idea what can happen. It's beyond most of our capability to disprove that the data sheet is incorrect in stating 1ua.

And also note that it is not *me* that is stating this 1ua, it is the manufacturer. Think about when you may have gone over the power supply rating of 6v or whatever it is. You might get away with it, you might not. But why take the chance.

There's also the possibility that the manufacturer improved the product over time, but i dont see any evidence of that on the data sheet or app notes, at least not yet.

Another interesting point is that the reference manual shows a circuit with a 100na current source in parallel with the AD input, and that is 10 times less than the max spec of 1ua which is of course 1000na. Yet they spec 10k as the max resistance. With 100na current source we could get away with 25k so why do they state 10k. That's what i mean, there are very strange conflicting data to be found there indicating that there was a mistake early in the data sheet publication.

And again, i am not arguing that you can not use 10k, i am arguing that if you want to meet the specs over the full temperature range then you need lower, and the solution is 2.5k with a 5v reference voltage, and lower with a lower reference voltage. And what we still dont know yet is if this leakage current changes with absolute input voltage level.

The problem is 2.5k sounds kinda low and people dont like that, so they want to accept 10k as the better value rather than investigate fully. For me higher works sometimes too, because that circuit application does not see the full temperature range.

BTW the application i always talk about uses a 50k resistor and a 50k thermistor in series to sense temperature and biased by a relatively stable power supply voltage of a few volts. So that works out to 25k input resistance for that circuit... and it works pretty nice :)
 
BTW the application i always talk about uses a 50k resistor and a 50k thermistor in series to sense temperature and biased by a relatively stable power supply voltage of a few volts. So that works out to 25k input resistance for that circuit... and it works pretty nice :)

Because you're not reading it rapidly, and probably not switching inputs either, this cures the capacitor charging problem.

Get a couples of pots , 4.7K would be fine as they meet the maximum source specification, and wire then across 0V and 5V, with the sliders going to PIC inputs. Write a quick program to display the two values on an LCD (or RS232 to a PC etc.)

Now move the pots, the two voltage readings should move entirely independently.

Not add series resistors (try 100K for a start) from sliders to inputs, and repeat the same tests - you will find that (dependent on the pots positions) than they now no longer work independently. If you now mod the program to allow a longer settling time when switching inputs (such as you'd use when reading a thermistor) you'll find that they are independent again. You might be surprised how long the settling periods need to be with high value sources.
 
Hi again Nigel,


I think i understand what you are doing there, and i think i agree with that. If i wrote my other posts correctly what i was trying to get across was that the equivalent internal current source that represents the leakage current of an analog pin came into question as to changing the accuracy of the reading over the full temperature range, and the only way to make absolutely sure it does not change the basic accuracy of the PIC chip analog to digital converter would be to make sure that any signal current can override the leakage current even when we consider the highest possible leakage current for the chip. So i do agree with the timing issues, but i also interject that the leakage current is also an issue in determining the best value (given the app requirements of course) for the project.

I can provide a drawing if think that would help.
 
Hi again Nigel,


I think i understand what you are doing there, and i think i agree with that. If i wrote my other posts correctly what i was trying to get across was that the equivalent internal current source that represents the leakage current of an analog pin came into question as to changing the accuracy of the reading over the full temperature range, and the only way to make absolutely sure it does not change the basic accuracy of the PIC chip analog to digital converter would be to make sure that any signal current can override the leakage current even when we consider the highest possible leakage current for the chip. So i do agree with the timing issues, but i also interject that the leakage current is also an issue in determining the best value (given the app requirements of course) for the project.

I can provide a drawing if think that would help.

Not really needed, my concern is only that the possible leakage current is fairly theoretical, so 'may' be a problem - the capacitor issue is a more serious concern.

You could also use the same method I suggested above to check for potential leakage problems, leave the pot set where it is and change the series resistor value.
 
Not really needed, my concern is only that the possible leakage current is fairly theoretical, so 'may' be a problem - the capacitor issue is a more serious concern.

You could also use the same method I suggested above to check for potential leakage problems, leave the pot set where it is and change the series resistor value.

Hello again Nigel,

Nice to see this in the uC section finally. Thanks for moving it.

When you say 'may' that is exactly what i am talking about. They state that 1ua for a reason, and i'd like to hear your take on that spec.

Apparently at one time you agreed with me fully:

The source impedance should be no more than 2.5K, your divider is considerably more than that!. This will restrict how fast you can switch between channels, and may have some bearing on accuracy.

If you can't use a lower value potential divider, you should consider an opamp buffer between the PIC and divider - check my analogue tutorial!.

Also, if you check the 18F series (i'd have to look up some of those after years of not reading) they do in fact state 2.5k in the calculation, yet they show the exact same circuit and same leakage current! It's interesting that Microchip came up with two different 'maximum' values for the same resistance in the same circuit. And also interesting is that the hold capacitance is smaller for the 18F and that would theoretically allow a HIGHER than 10k if in fact we were mainly concerned with the acq time over the leakage current spec. It's also interesting that is many data sheets they actually come right out and state that the value of Rs is chosen to meet the leakage pin requirements.
 
Hello again Nigel,

Nice to see this in the uC section finally. Thanks for moving it.

When you say 'may' that is exactly what i am talking about. They state that 1ua for a reason, and i'd like to hear your take on that spec.

Test it and see.

Apparently at one time you agreed with me fully:

The quote said nothing of the kind.

Also, if you check the 18F series (i'd have to look up some of those after years of not reading) they do in fact state 2.5k in the calculation, yet they show the exact same circuit and same leakage current! It's interesting that Microchip came up with two different 'maximum' values for the same resistance in the same circuit. And also interesting is that the hold capacitance is smaller for the 18F and that would theoretically allow a HIGHER than 10k if in fact we were mainly concerned with the acq time over the leakage current spec. It's also interesting that is many data sheets they actually come right out and state that the value of Rs is chosen to meet the leakage pin requirements.

Again - check it and see - but 2.5K is to do with fast charge/discharge of the sample and hold capacitor. far more than anything else.
 
...
What else would be interesting to test is if this leakage current changes with input voltage. For example, what is it at 4.9v input and what is it at 0.1v input.
...

That's a very good point. Just guessing, but I would think there would be variance in the leakage depending on the pin voltage. Probably leaking IN to the pin at low voltages, and OUT of the pin at higher voltages?

IF that is the case, and you set the ADC to generally read somewhere around the middle 2.5v (which I usually do) then the pin leakage may be close to zero.

It would not be hard to test with a 1uA ammeter and a PIC and a pot. :)

But generally regarding the "max" conditions in the datasheet, Microchip are very conservative. It's not unusual for the real operating value to be many times less than the datasheet "max" value. :)
 
Hello again Nigel and MrRB,

Some good points, i'll reply in reverse order...


That's a very good point. Just guessing, but I would think there would be variance in the leakage depending on the pin voltage. Probably leaking IN to the pin at low voltages, and OUT of the pin at higher voltages?

IF that is the case, and you set the ADC to generally read somewhere around the middle 2.5v (which I usually do) then the pin leakage may be close to zero.

It would not be hard to test with a 1uA ammeter and a PIC and a pot. :)

But generally regarding the "max" conditions in the datasheet, Microchip are very conservative. It's not unusual for the real operating value to be many times less than the datasheet "max" value. :)

Yeah a 1ua meter :)

Regarding the max condition for the leakage current, you are saying that Microchip doesnt know
how to properly rate their chips so it's ok to second guess what they really meant. But my
point was not to use a resistor value that "probably" works, but to use a resistor that would
"absolutely" work, and that would work over the full temperature range.
If you can say that 1ua is actually higher than what we might would see, then i could
say that 1ua is actually lower than what we might see. To test this we'd have to have
100 or more chips from several production runs.

It's also interesting that if we read some of the data sheets as requiring a "max 10k potentiometer" then
it all works out because the max impedance of a 10k pot is 2.5k, what a coincidence :)
And more recent data sheets state 2.5k even though they left 10k in the example :)

Test it and see.

The quote said nothing of the kind.

Again - check it and see - but 2.5K is to do with fast charge/discharge of the sample and hold capacitor. far more than anything else.

Well i said 2.5k and you said 2.5k, so i figured you were agreeing. But it appears that you were
only agreeing to the 'timing' part of the requirement. So which do you prefer then, 10k or 2.5k ?

I'd like to know what you believe this resistor value does for the timing. For example,
if we use 2.5k, 10k, or say 25k, what is the difference if the application required sample
time is 10 milliseconds?

Also:
1. What value resistor would i use if the application sample time was 1 full second?
2. What value resistor would i use if the application sample time had to be as fast as possible for the PIC chip?
 
Well i said 2.5k and you said 2.5k, so i figured you were agreeing. But it appears that you were
only agreeing to the 'timing' part of the requirement. So which do you prefer then, 10k or 2.5k ?

The original A2D specs called for 2.5K maximum, so that's what I consider the maximum spec for high speed.

I'd like to know what you believe this resistor value does for the timing. For example,
if we use 2.5k, 10k, or say 25k, what is the difference if the application required sample
time is 10 milliseconds?

Test it and see.

Also:
1. What value resistor would i use if the application sample time was 1 full second?

Again, test it and see.

2. What value resistor would i use if the application sample time had to be as fast as possible for the PIC chip?

No higher than 2.5K - the specification is for maximum speed (and nothing to do with possibly minute leakage).

The A2D tests I did were a LONG, LONG time ago - back on the second ever EEPROM based PIC, the 16F877 when it initially came out (the first, and only for a long time, was the 16C84).
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top