Sonsivri

Electronics => Projects => Topic started by: acinonix14 on March 28, 2015, 07:47:16 07:47



Title: Read A/D avr values in noisy enviroments
Post by: acinonix14 on March 28, 2015, 07:47:16 07:47
Hi,

I have develop a simply thermometer (PS:5V) with avr and ntc resistor 4.7K through voltage divider.
I am using the A/D channel of avr and use the Steinhart-Hart Method.This works perfectly.

However when I put it close to a/c line 220V without any connection with the line, the measured value is not steady.
Of course the temperature is not changed, so I think the A/C line creates extra parasite noise and the avr measures this?

Any ideas how to cut this noise?

Thanks,


Title: Re: Read A/D avr values in noisy enviroments
Post by: Wizpic on March 28, 2015, 08:06:54 08:06
Try placing a 10Uf cap across the A/D pin and GND or a 100N cap and see if that helps


Title: Re: Read A/D avr values in noisy enviroments
Post by: wellnerson1 on March 28, 2015, 08:21:38 08:21
Try with a soft filter, a simple one like moving average filter. It will give good results under noisy environs.


Title: Re: Read A/D avr values in noisy enviroments
Post by: Fab66 on March 28, 2015, 04:34:43 16:34
Try with a soft filter, a simple one like moving average filter. It will give good results under noisy environs.

Hi, you can found more information here :

http://www.analog.com/media/en/technical-documentation/dsp-book/dsp_book_Ch15.pdf

And thanks for this advice, i need it also in my project.

Fab


Title: Re: Read A/D avr values in noisy enviroments
Post by: Gallymimu on March 28, 2015, 05:49:32 17:49
An analog filter with a BIG capacitor like the suggested 10uF as well as a low frequency moving average filter can work wonders for you.  Be careful as the moving average filter won't help much if it doesn't have a cutoff frequency below 50/60Hz so it is very sampling rate dependent.  i.e. if you are sampling at 1KHz then you would want a 128 point moving average filter to have a cutoff well below the line frequency.  A power of 2 filter is always a great way to go since you can summ and then just bit shift, it makes for a fast filter.

Also you could consider a digital notch filter at the frequency you want to take out.  There are IIR and FIR implementations of notch filters you could try, but if you don't have any DSP background it could be confusing to understand what it's doing.


Title: Re: Read A/D avr values in noisy enviroments
Post by: Ichan on March 28, 2015, 07:30:02 19:30
PCB layout also play important role on induced noise, and try to shield your thermometer device.

-ichan


Title: Re: Read A/D avr values in noisy enviroments
Post by: PeterMcMonty on March 29, 2015, 01:47:28 01:47
I agreed with almost everybody: filter, filter and filter furthermore! Both analog (an RC lowpass is of great value in its simplicity) and digital!

Another hint: temperature variations are so slow that the filter cutoff frequency could be as low as 1 Hz, making possible a huge attenuation at 50-60 Hz. Keep the filter as close as possible to the AD converter input and keep care of PCB layout, as suggested by Ichan.

On my experience, a good average done in software helps furthermore. Depending on your application, but I don't think it should necessary be a running average.

You could take, for example, the sum of 256 measures on a two or three bytes variable and then simply discard the last significant byte.

A refinement could be rounding to the nearest integer:
if the MSB of the discarded byte is 1 then increment the result by one else continue.


Title: Re: Read A/D avr values in noisy enviroments
Post by: PeterMcMonty on March 29, 2015, 03:22:54 03:22
BTW, thanks to Fab66 for linking chapter 15 of that dsp book (obsolete in the site of Analog Device, but you can reach chapters 1 to 33 simply by changing name of pdf at the end of address line in your browser).

For those who are interested in that book, that is:

The Scientist and Engineer's Guide to Digital Signal Processing
By Steven W. Smith, Ph.D.

you can read and/or download all the chapters from 1 to 34 (yes, chapter 34 is not on Analog Device website or it has a different filename) from this page, that is the download page of the book, I think owned by the author himself:

http://www.dspguide.com/download.htm

In the same page you can also download programs and other documents as exercises.


Title: Re: Read A/D avr values in noisy enviroments
Post by: Gallymimu on March 29, 2015, 07:03:51 19:03
BTW, thanks to Fab66 for linking chapter 15 of that dsp book (obsolete in the site of Analog Device, but you can reach chapters 1 to 33 simply by changing name of pdf at the end of address line in your browser).

For those who are interested in that book, that is:

The Scientist and Engineer's Guide to Digital Signal Processing
By Steven W. Smith, Ph.D.

you can read and/or download all the chapters from 1 to 34 (yes, chapter 34 is not on Analog Device website or it has a different filename) from this page, that is the download page of the book, I think owned by the author himself:

http://www.dspguide.com/download.htm

In the same page you can also download programs and other documents as exercises.

Hey that is a GREAT resource!!  The chapters are concise and seem pretty well organized with relevant figures.


Title: Re: Read A/D avr values in noisy enviroments
Post by: Magnox on March 29, 2015, 08:31:31 20:31
I have that book in my collection in a single pdf...

http://www.sonsivri.to/forum/index.php?topic=59992

now it's here.


Title: Re: Read A/D avr values in noisy enviroments
Post by: iot on March 30, 2015, 03:34:19 03:34
In some AVRs there is an option to sleep the MCU to reduce the noise during ADC phase.

Have you tried with that option?


Title: Re: Read A/D avr values in noisy enviroments
Post by: Gallymimu on March 30, 2015, 04:01:06 04:01
In some AVRs there is an option to sleep the MCU to reduce the noise during ADC phase.

Have you tried with that option?

That is likely not his problem since the noise was only an issue when he was near line voltages.


Title: Re: Read A/D avr values in noisy enviroments
Post by: acinonix14 on March 30, 2015, 01:52:48 13:52


Gallymim
An analog filter with a BIG capacitor like the suggested 10uF as well as a low frequency moving average filter can work wonders for you.  Be careful as the moving average filter won't help much if it doesn't have a cutoff frequency below 50/60Hz so it is very sampling rate dependent.  i.e. if you are sampling at 1KHz then you would want a 128 point moving average filter to have a cutoff well below the line frequency.  A power of 2 filter is always a great way to go since you can summ and then just bit shift, it makes for a fast filter.

Also you could consider a digital notch filter at the frequency you want to take out.  There are IIR and FIR implementations of notch filters you could try, but if you don't have any DSP background it could be confusing to understand what it's doing.
.

Is there any sample using the avr (or arduino) to build a notch filter with cutoff 60Hz? Or IIR and FIR? I am not a DSP guy but I would like to try build a filter in avr328. I make sampling every 20 msec but I can change it if its possible.

Thanks,


Title: Re: Read A/D avr values in noisy enviroments
Post by: SteveyG on March 30, 2015, 04:05:00 16:05
If your signal source is high impedance, it's very likely to easily pick up noise from external sources. You must have an anti-aliasing filter prior to the ADC, then sample the ADC at a high enough rate that you can filter the out of band signals and have them contribute to less than 1/2 LSB error.

In very noisy environments, a single pole filter will not be sufficient unless you can sample at 100's of kHz.


Title: Re: Read A/D avr values in noisy enviroments
Post by: mris99 on April 20, 2015, 08:24:10 20:24
Don't forget to filter also the analog power line (AVCC) thus it can also pickup noise.
Serial 10uH / parallel 100nF for example.
It is more important if you direct derive reference voltage from that (Vref = AVCC).


Title: Re: Read A/D avr values in noisy enviroments
Post by: Droneman1982 on May 05, 2015, 11:16:54 11:16
Try to use twisted pair leads and use a 50-60 Hz notch filter. Of course use a ground plane under your signal leads. Another possibility is to average 4^n samples obtaining n more bits (oversampling) than the ADC has.

A Low pass filter would also work, but it will slow down your response to the RC time constant of your filter. It depends on your application.

The best would be to switch to a I2C digital thermometer (following closely the board layout advised by the datasheet), this way you don't need to sample your data via the internal ADC


Title: Re: Read A/D avr values in noisy enviroments
Post by: acinonix14 on May 06, 2015, 05:24:11 05:24
Thanks guys,

I am using an extra RC filter in input and of course put 100nF to AREF pin.

Also I got 100 samples, sort all them and from sorted values I was getting the average of 20 samples between the 40 and 60 sample. With this version I cut off the spikes. The result it is impressive (about 0.1-0.2 C degree).



Title: Re: Read A/D avr values in noisy enviroments
Post by: Vineyards on May 06, 2015, 02:54:14 14:54
As SteveyG writes the input impedance is a very important factor. You could decide on what to use depending on:

1- Input impedance
2- Input signal level
3- Input noise level
4- Type of noise (AC, DC?)
5- Coupling type (wire, air)

There might be also be a ground loop problem that would necessitate galvanic isolation...


Title: Re: Read A/D avr values in noisy enviroments
Post by: Droneman1982 on May 13, 2015, 04:07:16 16:07
I would suggest you to use a multiple of 4 for the average

with 4 samples you "get" one extra LSB
with 16  two extra bits
with 64 tree extra bits
with 256 four extra bits


Title: Re: Read A/D avr values in noisy enviroments
Post by: Vineyards on May 13, 2015, 09:21:49 21:21
Droneman do you have a reference for that. Based on practical experience, I would say, if there is substantial noise in the signal path, going up to 256 samples, only marginally helps with the measurement accuracy. You have to tackle the problem at its roots. Perhaps a Kalman filter might help but it does demand certain prerequisites too.


Title: Re: Read A/D avr values in noisy enviroments
Post by: titi on May 14, 2015, 09:28:09 09:28
Hi,

I think this document explain how get more resolution for an ADC by using oversampling.

Best regards.


Title: Re: Read A/D avr values in noisy enviroments
Post by: Vineyards on May 14, 2015, 08:15:14 20:15
I know this document. It tells about stuff like white noise and how its presence actually improves resolution etc.
However, we are not talking about noise that will affect the LSB's here (e.g. Johnson's noise). I am talking about hefty noise and there is no easy cure for it.


Title: Re: Read A/D avr values in noisy enviroments
Post by: vern on May 15, 2015, 09:00:57 21:00
Try to make the measurement differential, not referred to GND.
If you only have a ground referred input use an Op-Amp to make a differential measurement and output a Ground referred voltage to your AD converter.
That helps a lot. I would also try to make the measurement rate an exact multiple of your AC Line frequency,
i.e if your line frequency is 50 Hz you would make the rate 5 Hz, 10Hz, etc.
The two frequencies will drift apart after a while, but for the short term this will keep the noise down since your measurement will always be in sync to the AC sine wave.


Title: Re: Read A/D avr values in noisy enviroments
Post by: Vineyards on June 02, 2015, 09:42:59 21:42
However, differential inputs have strict limitations on allowable input signal levels and if your noise problem is not moderate to small, you might damage the inputs. Use a LP filter made with two resistors hooked up to the inputs. Place three capacitors one between the differential inputs and the other two between either input and ground. Make the one in the middle 10 times greater than the value of the other two capacitors. (of course you need to calculate values) This the way to build a simple filter stage for differential amplifiers. If you are dealing with a high Z signal, you might as well forget about differential inputs or use the expensive INA series opamps.


Title: Re: Read A/D avr values in noisy enviroments
Post by: bytraper on June 04, 2015, 05:50:29 05:50
Could you possibly use a diode and cap and take average samples? Or possibly run dual inputs routed in parallel with filtering with use some logic as a buffer? We deal with this all the time in motor control boards as the back emf plays havok with the surrounding sensitive parts!


Title: Re: Read A/D avr values in noisy enviroments
Post by: Vineyards on June 04, 2015, 08:24:17 08:24
Are you talking about snubber diodes? A LP filter does averaging anyway. In my opinion, there is not a magical solution that answers all the questions. As I wrote before, it depends on signal characteristics environment etc.

For example, diodes are leaky components. They will effectively short a High Z signal if they are used as clamp etc. You need a buffer but then how will you protect the buffer. If it is an opamp you could put resistors on the input and if it is a voltage follower you could place a resistor between  non-inverting input and output rather than shorting these two. This way you could prevent excessive current flow through that component.

Posted on: June 04, 2015, 09:22:31 09:22 - Automerged

If problems persist, you need to galvanically isolate input from the rest of the circuit and the known methods for that are optical, inductive, capacitive isolation (ic's) as well as V/F, F/V converters.


Title: Re: Read A/D avr values in noisy enviroments
Post by: Vineyards on June 04, 2015, 12:23:09 12:23
Check out this link. There you can choose an opamp and see if it will work within desired voltage levels: http://analogplayground.com/diamond/


Title: Re: Read A/D avr values in noisy enviroments
Post by: 2N5109 on October 27, 2015, 02:24:38 02:24
Put 100uF capacitor across ntc 4.7k resistor. The noise is driving the ADC nonlinear so DSP filtering is not effective. Also need to determine if magnetic or electric field of AC 60 Hz is being pickupped. Could try metal shield around resistor+avr.
    --2N5109


Title: Re: Read A/D avr values in noisy enviroments
Post by: kreutz on October 27, 2015, 03:11:58 15:11
The complete DSP book (2nd Edition), mentioned early in the thread,  is in here:
 
http://ft-sipil.unila.ac.id/dbooks/The%20Scientist%20and%20Engineer's%20Guide%20to%20Digital%20Signal%20Process.pdf


Title: Re: Read A/D avr values in noisy enviroments
Post by: 2N5109 on December 02, 2015, 02:21:57 02:21
Current in 220v AC circuit is probably relatively high and coupling voltage into ADC input via its magnetic field and flux, v=-d(phi)/dt.  We need to know more about circuit arrangement. At low frequencies of 50 Hz, conductive shielding is not effective against magnetic fields, and probably interferes with whatever temperature measurement you make.

You could try to reduce  flux (INT(B*dA)) by considering the area that magnetic field is operating on and reducing it by putting wires close together.  Twisting them so there is cancellation in net integral will help also. It is difficult to know unless there is more detail description of problem.  

Attacking the problem at the source is important in this case since large induced voltage from 220VAC line could cause nonlinear response in the ADC which cannot be filtered by linear means described above.

--2N5109    


Title: Re: Read A/D avr values in noisy enviroments
Post by: witsanukai on January 06, 2016, 08:02:19 08:02
Can refer to below document too.

http://www.st.com/web/en/resource/technical/document/application_note/CD00211314.pdf

but almost on power line noise induce just apply 0.1uF capacitor at AVCC and ADC input and also implement moving average problem must disappear base on my experince.


Title: Re: Read A/D avr values in noisy enviroments
Post by: Vineyards on January 10, 2016, 12:05:41 00:05
Could you possibly use a diode and cap and take average samples? We deal with this all the time in motor control boards as the back emf plays havok with the surrounding sensitive parts!
Are you talking about snubber diodes? I think a simple LP filter would be a better choice for analog measurement circuits. However as mentioned earlier everything depends on what you want to measure. The difficulty here being, as input resistance and capacitance increase it becomes more and more difficult to put anything between the signal and the input. Because most components are tremendously leaky when high Z is involved. Even the high input capacitance or low input resistance of an opamp makes it unfeasable for use in high Z applications. For example, a typical pH probe produces ±414mV which is not a very low level signal however as the current from the pH probe is usually in the femtoampere range, you can not measure it correctly if you use an opamp having too high a Input bias current, or capacitance or too low resistance as much or all of the energy that is output will be leaked to the ground (or wherever) causing faulty measurements. Under such conditions it will take ages for the measurement stabilize if it ever can.

As a result leakage rate of a component will become very important. Diodes are particularly notorious for being leaky components so are electrolyte condensers.