Voltage spikes on PIC ADC PIN. - Page 1
Forum section: electronics / general

author: SajjadBro
author_rank: Contributor
timestamp: February 09, 2012, 06:17:49 am
content: Guys Please help me solving my problem. I have a simple setup on my bread board having PIC16f876A. I am using AN0 as ADC input and connected it to ground via 1.5k resistor. all other Pins are grounded and declared as digital input. PWM2 is activated on RC1 pin. of frequency 12KHz and duty cycle of 30%. Lm7805 is being used as regulator and 12Mhz crystal OSC is used with 27 pF caps..Now i am having voltage spikes on pin AN0 as pwm pulses goes from high to low. Solution?

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 09, 2012, 06:36:49 am
content: Quotedont use AN0 (analog ZERO)

author: amspire
author_rank: Super Contributor
timestamp: February 09, 2012, 06:48:46 am
content: Quote from: SajjadBro on February 09, 2012, 06:17:49 amYou first have to work out if the spikes are real or not. Connect the yellow trace scope probe to circuit 0V and see if the spikes are still there. Also remove the blue trace probe completely and see if the spikes go away.Richard.

author: SajjadBro
author_rank: Contributor
timestamp: February 09, 2012, 07:03:46 am
content: Quote from: Mechatrommer on February 09, 2012, 06:36:49 amWhy not?

author: SajjadBro
author_rank: Contributor
timestamp: February 09, 2012, 07:16:50 am
content: You first have to work out if the spikes are real or not. Connect the yellow trace scope probe to circuit 0V and see if the spikes are still there. Also remove the blue trace probe completely and see if the spikes go away.Richard.Ok i have connected the yellow channel to GND while blue channel was measuring the PWM. Still same result.I have disconnected the blue channel(even from the scope). and Spikes changed their behavior like in a delayed manner. I am posting the Pictures and also zoomed version of single spike.

author: DrGeoff
author_rank: Frequent Contributor
timestamp: February 09, 2012, 07:17:51 am
content: Also check your PSU decoupling, it could be getting in via the AIN voltage reference. What ref are you using? If you are doing ratiometric inputs, make sure you decouple the analog VCC and GND pins from the digital VCC and GND pins. Use ferrites and NPO caps.

author: SajjadBro
author_rank: Contributor
timestamp: February 09, 2012, 07:32:26 am
content: Quote from: DrGeoff on February 09, 2012, 07:17:51 amI m using a linear power source, it came with my small drill machine, 12V and 800mA. its just a transformer, rectifier and filter cap, out put is clean. i have put solid tantlum cap of 1uf near regulator and 0.01uf ceramic cap near vcc and vdd pins of controller. I m not measuring any thing yet, the AN0 pin is grounded via 1.5k resistor.What are NPO caps? and ferrites bead are like inductor so what value?My main guess is that what ever i do externally wont help because noise is being created inside and disturbing the ADC from inside!!! man i am stuck.

author: DrGeoff
author_rank: Frequent Contributor
timestamp: February 09, 2012, 07:41:15 am
content: I was talking about your Vref, not your regulator.Since this device uses the incoming supply to power the ADC, and if you have selected the internal supply as the Vref you had better make sure it is *very* clean.

author: DrGeoff
author_rank: Frequent Contributor
timestamp: February 09, 2012, 07:43:04 am
content: You should also make all your unused pins outputs, and set them to 0. That way you are less likely to couple noise through a high impedance input.

author: SajjadBro
author_rank: Contributor
timestamp: February 09, 2012, 08:15:34 am
content: Quote from: DrGeoff on February 09, 2012, 07:41:15 amOk two pictures here. one with PSU connected and one with not. i have set my scope on AC coupling mode so the first picture is having noise on top of my regulated signal. do note that i have removed my controller while measuring this. I put every value from 0.01uf - 10 uf but this noise is not going. the second picture is when no PSU is connected. Also do note that i have changed my PIC to 16f877A the bigger version of previous one. but still same problem.

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 09, 2012, 08:24:31 am
content: Quote from: SajjadBro on February 09, 2012, 07:03:46 ambecause its not in the errata note, and because you have to try other analog pin if its solved, if not, try to set/play the AN0 as output high (or low) and see if other adc read correctly.

author: DrGeoff
author_rank: Frequent Contributor
timestamp: February 09, 2012, 08:35:53 am
content: Quote from: SajjadBro on February 09, 2012, 08:15:34 amSo clean it up if it worries you. Looks like you are also getting a lot of radiated noise indiced into your measuring probes. Pretty common for this kind of thing. The spikes on your ADC channel have nothing to do with this, and are related directly to an output switch changing state (PWM output I think). My guess is that it is being coupled through either a nearby pin set to an input, or the PSU rail which is probably being used as Vref for the ADC. This is pretty basic stuff, particularly if you are using a breadboard. Normally during PCB layout you would take a lot of precautions to decouple the analogue supply rails from the digital supply rails, and run shielding tracks around the analogue input pairs.

author: SajjadBro
author_rank: Contributor
timestamp: February 09, 2012, 08:38:50 am
content: QuoteSame result on the other channels also. even when i grounded them directly i.e. short ADC pin to ground

author: SajjadBro
author_rank: Contributor
timestamp: February 09, 2012, 08:45:05 am
content: QuoteOk well can you lead me to some good tutorial how to decouple analog rails from digital rails.I couldn't find a good article specially with PCB examples. Else i think that this spike will bother my readings. Do you have similar experience or anyone here?and how would you shield a pcb track going to ADC pin?

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 09, 2012, 09:13:22 am
content: Quote from: SajjadBro on February 09, 2012, 08:38:50 ammeasurement problem then, some aspect DrGeoff has mentioned. please check both your circuit and probe for noise immunity.

author: DrGeoff
author_rank: Frequent Contributor
timestamp: February 09, 2012, 10:27:24 am
content: Quote from: SajjadBro on February 09, 2012, 08:45:05 amYes I have experience in this type of design. I'm not going to lead you through a tutorial on analogue design though. Go and find an Analog Devices data book and read up on how to layout circuit boards for analogue front ends and AD converters. They have some excellent material about guard rings, shielding and noise decoupling.You have not answred my questions about your ADC reference supply. I assume you have no idea about it and would suggest that you do some more reading and learn about why a reference supply for an ADC must be very clean and noise free.

author: SajjadBro
author_rank: Contributor
timestamp: February 09, 2012, 10:54:43 am
content: QuoteWell sorry for that. There are 2 pins for that Vref- and Vref +. I configured it in both way i.e. using its on chip references and then i configured it so that i can provide vref +/- my self. done both and same result. As i told you that 2mv or may be little more is on top of my regulated voltage and its not going away.

author: amspire
author_rank: Super Contributor
timestamp: February 09, 2012, 11:41:58 am
content: Quote from: SajjadBro on February 09, 2012, 07:16:50 amSo what you are seeing on the scope is probably nothing to do with the A/D pin, but it does look like there is a problem. It does look like the falling edge of the PWM, and sometimes the rising edge, is triggering a ringing or an oscillation, that is getting into the scope probably through the earth connections.Are the scope earth leads connecting to a 0V close to the micro?For the zoomed in image, it looks like you just expanded a slow capture as the triangular waveform looks like you need far more samples per cycle. You want to trigger off the spike, and turn the sweep speed up so you can get a good look at that sine-looking wave. Is it a constant amplitude for the whole period of the spike, or is it slowly falling off in amplitude through the spike?The PWM output alone with nothing connected to the PWM pin would be unlikely to generate this noise.If the amplitude is constant for the width of the spike, then something to do with the PWM, or something in sync with the PWM is oscillating. That is something worth tracking down. If the spike consists of a slowly decaying sine wave, then you probably have ringing associated with some inductance somewhere that can do with some damping.What else is connected to the PWM pin?Also start off with the oscilloscope connected and all the supplies off. You should be able to get some waveforms with less then 3mV noise, particularly if the scope probe is connected to the same point of the circuit as the probe's ground clip.Richard

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 09, 2012, 11:59:42 am
content: since you've mentioned you've pull the adc pin hard to ground and yet get the spike on the scope, probably you have long ground return probe picking up the spike (act as an inductor) from the breadboard. i suggest concentrate on shielding your probe and study about how transmission line works, loading effect etc (i'm not done on it yet) so you will stop blaming your circuit entirely.reduce ground return length by using the spring type if you have one. i will refer you to one of the member's site to get the idea how serious probing business is, not really directly related, but somehow related... herehttp://koti.mbnet.fi/jahonen/Electronics/DIY%201k%20probe/you also can search here where people provided link about tektronix probe xyz handbook (cant recall where), read thehttp://cds.linear.com/docs/Application%20Note/an47fa.pdfto get the feel what effect you can get from "not so good" probe. some people treat pwm (square signal) lightly esp at KHz freq (including me mostly), but theoritically, pwm has infinite spectrum of frequencies and harmonics. do it wrong, you'll get the "ring".

author: SajjadBro
author_rank: Contributor
timestamp: February 09, 2012, 12:30:19 pm
content: Quote from: amspire on February 09, 2012, 11:41:58 amWow just sitting there you almost analysed my problem correctly.Well one thing is sure that Spikes occur when PWM is on and when probe is connected to it. When i remove the blue channel then there are no spikes.There is noting connected to PWM channel, later i will only connect it with LCD LED via transistor.To some extent you are right that PWM has nothing to do with ADC, so i removed The scope probes and displayed directly the reading i am getting from ADC i.e. 0-1023. Now when i set PWM to 20kHz then i get error of 4-6 bits max. setting it to 10KHz gives 2bit error and setting it to 1KHZ gives only 1 bit error. What do you think?Well right now oscilloscope has 3 pins in its power jack, hot wire, neutral, and earth but my line connection has no earth.Unfortunately i just passed out of my University and this is my first scope and its only 25MHZ as i thought it will fulfill my requirements.Yes when i unplugged the supply (both +/-) from the bread board, even then there is noise upto 3mV. when scope probe is attached to its ground plug and nothing else then -800 microvolts. while they are still attached and i connect to any metal or wire then there is error up to 3mV.

author: IanB
author_rank: Super Contributor
timestamp: February 09, 2012, 04:16:16 pm
content: Quote from: SajjadBro on February 09, 2012, 12:30:19 pmIf your device has three pins in its power plug, itmustbe connected to an earthed mains outlet. It is extremely dangerous to do otherwise.QuoteWith no disrespect intended, that means you are what might be known as a greenhorn, or a tenderfoot, and have much yet to learn. At this point in your journey you are suffering from a severe lack of knowledge and understanding.And to be honest, if you are unaware that you should not connect a grounded mains plug to an ungrounded outlet then your university education was almost worthless. Perhaps you should tear up that piece of paper and start over?

author: SajjadBro
author_rank: Contributor
timestamp: February 09, 2012, 07:36:50 pm
content: Quote from: IanB on February 09, 2012, 04:16:16 pmI know what a ground pin is for safety purposes so when circuit in your metal casing malfunctions then the casing will be electrified but since you have a ground pin then all the current is directed to the ground. So i ask do you need any grounding in your plastic casing? Well all around the world there are many devices that have to pin sockets, no ground attached and they are working fine even before you.Its a good excuse to say " i dont mean any disrespect" and disrespect the other.I don't mean any disrespect (and i mean it)but if you can't contribute then don't bother to comment. thanks.

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 09, 2012, 07:45:59 pm
content: Quote from: SajjadBro on February 09, 2012, 07:36:50 pmno need, but the dso circuit inside probably connected.

author: Unknown
author_rank: Unknown
timestamp: February 09, 2012, 07:48:59 pm
content: Quote from: SajjadBro on February 09, 2012, 07:36:50 pmWhat about BNC sockets? Any I/O like USB? How did you determine insulation rating of the casing? All tests for both EMC and safety were done with the assumption that all grounded parts (like shielding) were at a safe potential relative to the user. This is no longer guaranteed if you operate it without ground connection. I wouldn't assume that the knobs, for example, were designed to provide protection against voltage transients as might be expected on mains circuits.

author: IanB
author_rank: Super Contributor
timestamp: February 09, 2012, 07:54:27 pm
content: Quote from: SajjadBro on February 09, 2012, 07:36:50 pmI meant no disrespect about you being fresh and having much to learn. We have all been in that place. It is no shame to admit your inexperience.But if you don't realize that if a device has a ground pin on the plug,then that pin is meant to be used, then surely I think you are very foolish. There is no other way to put it.

author: SajjadBro
author_rank: Contributor
timestamp: February 09, 2012, 09:28:11 pm
content: Quote from: IanB on February 09, 2012, 07:54:27 pmThe power cable came along with it has only two pins, but i had the one with three pins. So i think i did a wise thing, we purchased this house so i am assuming that there is no ground. As many people (electricians)here don;t bother while doing wiring(Its not my mistake) that's why i made a sure short assumption and considered the worst scenario.One more thing don't say something which demoralize other to excel. I have no shame to say that i am inexperienced for what i don't know but what i understand, i go to its depth.I think i have found one person in this community who likes to criticize instead of giving suggestions and bucking up. It is a request not to post for me ever, thanks and God bless you.

author: IanB
author_rank: Super Contributor
timestamp: February 09, 2012, 10:18:19 pm
content: OK, I apologize for my tone.But you must understand there is a danger to life here. There is a possibility, if something goes wrong, that you could die.An oscilloscope, if properly designed and manufactured, should have a three pin grounded mains connection. It is essential to connect the ground pin. Without it the oscilloscope may not work as well as it should, and may be dangerous to operate in some circumstances.There are often other electrical devices that have a three pin grounded mains connection. If they have one, they also must be connected to a grounded mains socket with a good earth.In many houses and homes, the electrical outlets may only have two pins. This was for a long time true in America, where electrical safety standards have historically been weak.However, houses and homes should at least havesomeoutlets with a three pin grounded connection. If there are none, it would be necessary not to use any appliances or devices with three pin plugs, or to have an electrician install some grounded outlets.

author: amspire
author_rank: Super Contributor
timestamp: February 10, 2012, 01:50:20 am
content: Quote from: SajjadBro on February 09, 2012, 12:30:19 pmSajjadBro,First, a 25MHz scope is a very useful scope. I have no problem with that.I hope you will not get upset by comments on safety from some people. There are many people in this forum who would be absolutely devastated if they heard that one of our members was badly hurt due to a lack of an appropriate safety warning. The motivation for warnings is a genuine concern for people, even if the concern comes across in the wrong way.The reason that the lack of an earthing system is a problem for oscilloscopes is that they are not "double insulated" so they are not designed to be safe without proper earth wiring. A single fault could make the ground on the oscilloscope live. In an normal earthed power system, this would blow a fuse, or trip an earth leakage breaker. Without a proper earth, an oscilloscope is just not designed to be safe. In this respect, test instruments like oscilloscope's are very different from double insulated appliances like TV's.Now lets get to how this can affect your measurements.What you are seeing on the scope is a lot of phantom noise that it seems can be triggered by low energy transitions. Without a proper scope earth, then the scope's circuitry is linked back to the mains via paths like the switching transformer's winding-to winding capacitance in series with its leakage inductance. The power supply for the test circuit also is similarly coupled to the mains. The behaviour of these types of couplings are unpredictable, but they definitely could ring in the way you are seeing in the spikes. It is possible that it will be hard to trust what you are seeing on the scope without some common earth connection.So what if your work bench had all the all the earth connections of the powerpoints shorted together, but not going to switchboard earth?Your scope may behave much better, but your whole bench is now far more dangerous. A failure in any one instrument can make the earth of everything on the bench live. If you then somehow touch something that is in electrical contact with the actual ground under the house you while you are using an instrument and you can get a shock.For now, as a next step in tracking down this noise problem, I think it is worth trying to power the test circuit from a battery rather then a power supply, and see if the waveforms become cleaner.When you were talking about the ADC, I didn't quite understand what kind of errors you meant. Is this the ADC variation with a constant applied voltage?Richard.

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 10, 2012, 06:02:16 am
content: Quoteyou havent seen worse yet! not only one person, but many!

author: SajjadBro
author_rank: Contributor
timestamp: February 10, 2012, 12:08:33 pm
content: QuoteThanks for make me more clear for the noise related to earth. So i opened an electrical socket and yes there was a green earth wire. My assumption was wrong and i will install another wire in my sockets which are on workbench. As you can see in the image the original power cable has an option for the earth pin but its not installed actually. but i will do as u said.I have tested my circuit on batteries even but same noise. Its just as i increase the PWM frequency the error goes up to 6 bits. under 2K frequency i only get hardly 1 bit error.

author: Unknown
author_rank: Unknown
timestamp: February 10, 2012, 11:06:57 pm
content: Quote from: SajjadBro on February 10, 2012, 12:08:33 pmThis looks like a CEE 7/7 plug. The hole would match the ground pin of a French socket. The metal on the sides would connect to ground in German sockets. It may not fit grounded sockets in your country, but it's clearly designed to work with grounded sockets.

author: SajjadBro
author_rank: Contributor
timestamp: February 12, 2012, 08:53:04 pm
content: Ok , i have made many experiments on PIC16f87x series. I have separated the Analog and Digital ground.All extra pins are set to digital input and are grounded. Earth connection was there, Ran my circuit even on battery.When PWM is on then there is error even up to 4 -6 bits.When PWM is off then the error is none.I didn't believe myself and always thought that i am doing something wrong but accidentally when i visited the microchip site for this controller, its was written "Not Recommended". Well this chip have some problem and i will try another chip of another model in future for that. for now i have turned off the PWM.If you guys faced the similar problem then do share. thanks.