Author Topic: Voltage spikes on PIC ADC PIN.  (Read 13815 times)

0 Members and 1 Guest are viewing this topic.

Offline SajjadBro

  • Contributor
  • Posts: 18
Voltage spikes on PIC ADC PIN.
« on: February 09, 2012, 06:17:49 am »
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?
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 10373
  • Country: my
  • reassessing directives...
Re: Voltage spikes on PIC ADC PIN.
« Reply #1 on: February 09, 2012, 06:36:49 am »
Quote
Solution?
dont use AN0 (analog ZERO)
It's extremely difficult to start life.. one features of nature.. physical laws are mathematical theory of great beauty... You may wonder Why? our knowledge shows that nature is so constructed. We simply have to accept it. One could describe the situation by saying that... (Paul Dirac)
 

Offline amspire

  • Super Contributor
  • ***
  • Posts: 3802
  • Country: au
Re: Voltage spikes on PIC ADC PIN.
« Reply #2 on: February 09, 2012, 06:48:46 am »
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?

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.
 

Offline SajjadBro

  • Contributor
  • Posts: 18
Re: Voltage spikes on PIC ADC PIN.
« Reply #3 on: February 09, 2012, 07:03:46 am »
Quote
Solution?
dont use AN0 (analog ZERO)

Why not?
 

Offline SajjadBro

  • Contributor
  • Posts: 18
Re: Voltage spikes on PIC ADC PIN.
« Reply #4 on: February 09, 2012, 07:16:50 am »

[/quote]

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.
[/quote]

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.
 

Offline DrGeoff

  • Frequent Contributor
  • **
  • Posts: 709
  • Country: au
    • AXT Systems
Re: Voltage spikes on PIC ADC PIN.
« Reply #5 on: February 09, 2012, 07:17:51 am »
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.
Was it really supposed to do that?
 

Offline SajjadBro

  • Contributor
  • Posts: 18
Re: Voltage spikes on PIC ADC PIN.
« Reply #6 on: February 09, 2012, 07:32:26 am »
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.

I 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.
 

Offline DrGeoff

  • Frequent Contributor
  • **
  • Posts: 709
  • Country: au
    • AXT Systems
Re: Voltage spikes on PIC ADC PIN.
« Reply #7 on: February 09, 2012, 07:41:15 am »
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.
Was it really supposed to do that?
 

Offline DrGeoff

  • Frequent Contributor
  • **
  • Posts: 709
  • Country: au
    • AXT Systems
Re: Voltage spikes on PIC ADC PIN.
« Reply #8 on: February 09, 2012, 07:43:04 am »
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.
Was it really supposed to do that?
 

Offline SajjadBro

  • Contributor
  • Posts: 18
Re: Voltage spikes on PIC ADC PIN.
« Reply #9 on: February 09, 2012, 08:15:34 am »
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.

Ok 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.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 10373
  • Country: my
  • reassessing directives...
Re: Voltage spikes on PIC ADC PIN.
« Reply #10 on: February 09, 2012, 08:24:31 am »
Quote
Solution?
dont use AN0 (analog ZERO)
Why not?
because 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.
It's extremely difficult to start life.. one features of nature.. physical laws are mathematical theory of great beauty... You may wonder Why? our knowledge shows that nature is so constructed. We simply have to accept it. One could describe the situation by saying that... (Paul Dirac)
 

Offline DrGeoff

  • Frequent Contributor
  • **
  • Posts: 709
  • Country: au
    • AXT Systems
Re: Voltage spikes on PIC ADC PIN.
« Reply #11 on: February 09, 2012, 08:35:53 am »
Ok 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.

So 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.

Was it really supposed to do that?
 

Offline SajjadBro

  • Contributor
  • Posts: 18
Re: Voltage spikes on PIC ADC PIN.
« Reply #12 on: February 09, 2012, 08:38:50 am »
Quote
because 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.

Same result on the other channels also. even when i grounded them directly i.e. short ADC pin to ground :(
 

Offline SajjadBro

  • Contributor
  • Posts: 18
Re: Voltage spikes on PIC ADC PIN.
« Reply #13 on: February 09, 2012, 08:45:05 am »
Quote
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.

Ok 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?
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 10373
  • Country: my
  • reassessing directives...
Re: Voltage spikes on PIC ADC PIN.
« Reply #14 on: February 09, 2012, 09:13:22 am »
Quote
because 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.
Same result on the other channels also. even when i grounded them directly i.e. short ADC pin to ground :(
measurement problem then, some aspect DrGeoff has mentioned. please check both your circuit and probe for noise immunity.
It's extremely difficult to start life.. one features of nature.. physical laws are mathematical theory of great beauty... You may wonder Why? our knowledge shows that nature is so constructed. We simply have to accept it. One could describe the situation by saying that... (Paul Dirac)
 

Offline DrGeoff

  • Frequent Contributor
  • **
  • Posts: 709
  • Country: au
    • AXT Systems
Re: Voltage spikes on PIC ADC PIN.
« Reply #15 on: February 09, 2012, 10:27:24 am »
Quote
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.

Ok 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?

Yes 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.
« Last Edit: February 09, 2012, 10:29:47 am by DrGeoff »
Was it really supposed to do that?
 

Offline SajjadBro

  • Contributor
  • Posts: 18
Re: Voltage spikes on PIC ADC PIN.
« Reply #16 on: February 09, 2012, 10:54:43 am »

Quote

Yes 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.

Well 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.
 

Offline amspire

  • Super Contributor
  • ***
  • Posts: 3802
  • Country: au
Re: Voltage spikes on PIC ADC PIN.
« Reply #17 on: February 09, 2012, 11:41:58 am »

Quote

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.

So 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

 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 10373
  • Country: my
  • reassessing directives...
Re: Voltage spikes on PIC ADC PIN.
« Reply #18 on: February 09, 2012, 11:59:42 am »
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... here http://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 the http://cds.linear.com/docs/Application%20Note/an47fa.pdf to 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".
It's extremely difficult to start life.. one features of nature.. physical laws are mathematical theory of great beauty... You may wonder Why? our knowledge shows that nature is so constructed. We simply have to accept it. One could describe the situation by saying that... (Paul Dirac)
 

Offline SajjadBro

  • Contributor
  • Posts: 18
Re: Voltage spikes on PIC ADC PIN.
« Reply #19 on: February 09, 2012, 12:30:19 pm »

Quote

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.

So 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


Wow 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.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 10373
  • Country: us
Re: Voltage spikes on PIC ADC PIN.
« Reply #20 on: February 09, 2012, 04:16:16 pm »
Well right now oscilloscope has 3 pins in its power jack, hot wire, neutral, and earth but my line connection has no earth.

If your device has three pins in its power plug, it must be connected to an earthed mains outlet. It is extremely dangerous to do otherwise.

Quote
Unfortunately i just passed out of my University

With 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?
I'm a ChemE--I know all about the flow of fluids.
 

Offline SajjadBro

  • Contributor
  • Posts: 18
Re: Voltage spikes on PIC ADC PIN.
« Reply #21 on: February 09, 2012, 07:36:50 pm »
Well right now oscilloscope has 3 pins in its power jack, hot wire, neutral, and earth but my line connection has no earth.

If your device has three pins in its power plug, it must be connected to an earthed mains outlet. It is extremely dangerous to do otherwise.

Quote
Unfortunately i just passed out of my University

With 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?

I 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.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 10373
  • Country: my
  • reassessing directives...
Re: Voltage spikes on PIC ADC PIN.
« Reply #22 on: February 09, 2012, 07:45:59 pm »
So i ask do you need any grounding in your plastic casing?
no need, but the dso circuit inside probably connected.
It's extremely difficult to start life.. one features of nature.. physical laws are mathematical theory of great beauty... You may wonder Why? our knowledge shows that nature is so constructed. We simply have to accept it. One could describe the situation by saying that... (Paul Dirac)
 

alm

  • Guest
Re: Voltage spikes on PIC ADC PIN.
« Reply #23 on: February 09, 2012, 07:48:59 pm »
I 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.
What 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.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 10373
  • Country: us
Re: Voltage spikes on PIC ADC PIN.
« Reply #24 on: February 09, 2012, 07:54:27 pm »
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.

I 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.
I'm a ChemE--I know all about the flow of fluids.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf