PIC power supply capacitor puzzle - Page 1
Forum section: electronics / general

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 06, 2018, 12:14:30 pm
content: In my temperature project (PIC16F1827 and LM35) the PIC is reading the voltage at the LM35 with an accuracy of about +/-1.0degC - about what the tolerance should be, I guess.I had previously noticed that the accuracy was more like +/-0.1degC and the only thing I changed was to add a 100uF electrolytic cap across the power supply (AA batteries) whereas previously I had none.So, I replaced this capacitor with a 100nF PET film cap (micro to nano so a thousand times less) and, hey presto! The PIC is now reading back at the original accuracy of +/-0.1degC and everything else is fine.How can this be?

author: NorthGuy
author_rank: Super Contributor
timestamp: July 06, 2018, 12:46:01 pm
content: If you use VDD as a voltage reference for ADC then all the measurements are relative to VDD and thus all the noise on VDD gets reflected in your ADC readings.However, don't mistake the smoothness of readings over time for accuracy.

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 06, 2018, 01:19:15 pm
content: No, I use the internal FVR and have been monitoring the temp vs a quality thermometer.

author: NorthGuy
author_rank: Super Contributor
timestamp: July 06, 2018, 01:48:00 pm
content: Quote from: PerranOak on July 06, 2018, 01:19:15 pmInteresting. Internal FVR only has 8% accuracy according to the datasheet.Anyway, I suggest trying an external reference and see if this alleviates the VDD influence. While you have an external reference connected, you can setup ADC to measure FVR directly (ADC channel 0x1f). Then you will know how accurate the FVR is and if it is influenced by the VDD noise or not.

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 06, 2018, 04:26:58 pm
content: OK great, thank you.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: July 06, 2018, 09:26:32 pm
content: Note that a measurement done with one source (the LM35) and one measuring device (the PIC) is not statistically significant; it isn't even a statistical set!You probably got lucky on the parts you have.Regarding the capacitor, it's impossible to tell without a circuit, layout, and preferably some waveforms. These are microsecond scale differences (this is apparent from the capacitor value), not something you can figure out with a DMM, and maybe not even from a schematic alone (hence layout too).Tim

author: wraper
author_rank: Unknown
timestamp: July 06, 2018, 09:39:13 pm
content: Quote from: PerranOak on July 06, 2018, 12:14:30 pmWalt, so initially you weren't using decoupling capacitor(s) at all?

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 09, 2018, 12:01:47 pm
content: Yes, that's right. In my enthusiasm to build it I forget entirely to put any cap in anywhere!The only reason I did put one in was when I had trouble with the first reading being way out (even though later readings were fine) that someone suggested the 100uF cap.

author: Wilksey
author_rank: Super Contributor
timestamp: July 09, 2018, 12:33:38 pm
content: Just put your 100n in parallel with the 100u (100n closer to the PIC).

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 09, 2018, 06:56:48 pm
content: Quote from: PerranOak on July 06, 2018, 12:14:30 pmDoes that mean that there were no decoupling cap close to the Vdd pin of the PIC?

author: wraper
author_rank: Unknown
timestamp: July 09, 2018, 07:34:34 pm
content: Quote from: PerranOak on July 09, 2018, 12:01:47 pmSo why are you surprised by this. Even if MCU still works without decoupling, ADC certainly cannot maintain it's performance with unstable power.

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 09, 2018, 08:34:59 pm
content: But the power is four AA batteries, fully charged. Why would it be unstable?Anyway, the mad thing is that it worked better when there were no caps in sight. It reminds me of a Dave vid where he removed nearly all decoupling caps from something (can't remember what) and it worked fine.

author: wraper
author_rank: Unknown
timestamp: July 09, 2018, 08:49:46 pm
content: You rather should compare how much effective resolution you get (noise free bits).QuoteThink about their internal resistance and low long wires are + length of the batteries. 100uF cap is no good for decoupling, too much inductance. Besides that, don't forget that PIC16F1827 analog voltage reference has -8/+6% accuracy.

author: Wilksey
author_rank: Super Contributor
timestamp: July 10, 2018, 11:54:59 am
content: Yeah, to show you don't need all of the caps they've put on, but you need some!!There are so many internal clocks and calculations that go on you need stable power.Why do you think that just because you have batteries that the device is automatically stable? If anything it'll give you bulk but not decoupling properties.

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 10, 2018, 02:43:32 pm
content: Thanks both.So, I thought that larger caps were to smooth switched supplies, etc. and therefore not needed with a battery.I guess then that the 100nF is doing the decoupling that may be needed and the 100uF was doing I-don't-know-what to reduce accuracy.I see that I must've been lucky with the actual components to get such accuracy and consistency over temp and time.BTW how do you decide what value of cap should be used for decoupling?

author: Wilksey
author_rank: Super Contributor
timestamp: July 10, 2018, 05:02:53 pm
content: RTFM.Most datasheets will tell you what you need for the device, the PIC datasheet has some good application examples with component values for the surrounding peripheral, standard rule of thumb I go by, 100nF on VDD/AVDD pins to the associated GND pins, there are other scenarios where you might want to add a 10nF or a bulk capacitor to a supply, I always make sure that the smallest value is nearest the power pins on the IC.

author: rx8pilot
author_rank: Super Contributor
timestamp: July 10, 2018, 05:13:02 pm
content: Quote from: PerranOak on July 09, 2018, 08:34:59 pmThe AA battery is stable, the switching noise is created by the PIC itself. That is why decoupling caps need to be placed as close to the device as possible. The tiny little gulps of current the PIC needs for each transistor cannot make it from the battery all the way to the PIC fast enough so the voltage drops during that time. The local bypass cap will supply those tiny currents while the power source and all the inductance/resistance/capacitance along the way catch up.

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 11, 2018, 12:23:13 pm
content: Thank both, I think I might be getting it!Ah yes I did that but the datasheet for the 16F1827 has no examples of actual circuits and this is the only one I've used.So, a lower value cap close to the power pins AND a larger one across the power supply somewhere?

author: Wilksey
author_rank: Super Contributor
timestamp: July 11, 2018, 06:29:47 pm
content: Typically yes, lower values (pF range) are also used for EMC to filter different frequencies.The decoupling removes "noise", so big bulky caps for storage, smaller one to get rid of noise, less noise = more stable.I'm generalising, but you get the idea!