AVR 50/60hz rejection/suppression for ADC

Go To Last Post
26 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have been looking at how the delta sigma ADC's have 50/60hz rejection 'built in' in some units.  I was wondering how best to do some form of 50/60hz rejection for the AVR's ADC for a single ended input.  I have a couple of ADC channels that will be used in a noisy environment with the mains AC close by.

 

My immediate thought would be a simple 10hz low pass RC, or band reject, but depending on the size of the R and C this could slow down conversion times as one would have to wait for the Cap(s) to charge/discharge to a steady state.

 

I admit I have no idea on how this could be done in code, if at all.

 

Just thinking out loud.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the issue is what is it that you are monitoring, or more importantly, what is the bandwidth of the signal?

 

If it is a slowly changing signal, BW < 10 Hz, then the 10 Hz LPF you mentioned would be fine.

It doesn't matter how long it takes to charge the cap, the issue is the frequency response of the filter, which is based upon the frequency content of the signal.

 

You can't, for example, pass a 50 Hz -10 KHz audio signal through the system with a 10 Hz LPF on the front end, it will attenuate your signal.

 

If your signal has frequency content above 50/60 Hz, such as the audio signal mentioned above, then an option is to use a band reject filter. 

Like all filters, there are simple versions, and more complex versions, with a narrower rejection bandwidth.

Unfortunately, this approach alters the input signal.

But such is life when the noise overlaps the input signal.

 

The band rejection filter could be done either in the analog front end before the ADC, or it could be done digitally, after the ADC.

Choice is yours.

 

Building a few, analog might be easier.

Building 1000's, it might be worth the software development time.

Analog might need tweaking, and might drift with temperature, etc.

Software isn't as sensitive to such issues.

 

Digital filtering generally requires a fast processor, to do it in pseudo-real time.

This is where the DSP/uC chips excel.

This is truly their market.

 

Lower performance digital filtering can certainly be done with slower speed AVR's, instead of super fast ARM's and DSPs.

An example would be DTMF decoding done with (slow) 8-bit uC's.

 

Finally, if the 50/60 Hz component of the input signal is really important, then one can sometimes set up a system to capture "just" the 50/60 Hz noise, without capturing the signal, and separately capture the desired signal, which includes the noise.  You then scale the noise and subtract it from the input signal.  This, in theory, allows you to retain the 50/60 Hz component of the input signal, instead of completely removing it.  This is the theory of active noise reduction microphones, headsets, environments, etc.  For most signals, and purposes, this is far overkill, and not needed.

 

Obviously with the Mains close by you want to shield your input signal cables, watch your ground planes and ground paths, etc.

 

JC

 

Edit:

Putting a uC with an ADC in a faraday cage, as close as possible to the signal source, so you can get the cleanest signal possible into the digital domain as soon as possible is often a good approach.

 

JC

 

 

 

Last Edited: Wed. Apr 1, 2015 - 04:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can think of 2 plans: a hi Q notch at 60Hz, and a 16.666667 ms delayed signal inverted and added to the input signal.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it is a slowly changing signal, BW < 10 Hz, then the 10 Hz LPF you mentioned would be fine.

Yes the signals are relatively 'slow' DC components.  I also had thought about using low slew rate OP-amps as well, but I do need rail to rail operation and none of the R/R units are pokey slow.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
60Hz ... 16.666667 ms

But Jim said 50/60 Hz.

 

So a question is: does it really need to be able to cope with both?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So a question is: does it really need to be able to cope with both?

Yes it does.  I think I will just do a simple low pass filter.  Passive or active remains to be seen

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if you have a slowly varying DC waveform then its ideal to use a software filter, its just an RC circuit discretised and you end up with two coefficients which are the sample rate (Ts) and the RC time constant (Tau), I can bore you to death if you like! other people call the coefficients k and (1-k) i think

 

You can play around with the values and alter the response, make completely different measurement systems follow the same response if you desire, the simple first order RC filter is very good for many things but a bit more work and you can go higher order if you need to without touching a component, hell you can implement a Kalman filter and bring a man back from the moon!, all in software

 

i never implemented a notch filter in software you have got me interested, I think software filters are amazing, they are very good for mitigating EMI glitches and help pass immunity standards, i think having both hardware and software is the best thing

 

The thing is though with interference and EMC is that its common mode voltage/currents through the parasitics where standard differential mode filters do nothing hence the EMC power filter is very important

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

60Hz suppression with a delta-sigma ADC is achieved by averaging over a time interval equal to N (integer) line cycles. If you use N = 6 for 60Hz line, then that also happens to be N = 5 for a 50Hz line. So, you kill 2 birds with one stone. Averaging is a key part of delta-sigma so it is just an extension of what needs to be done anyway, with some attention to clock rates.

 

The down side is slow response. But, detla-sigma ADC technology has been positioned in the slow speed, high resolution corner of the "spec matrix" and that is what you get. There are faster delta-sigma devices but they do not have the line rejection.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Wed. Apr 1, 2015 - 11:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if 50/60Hz is on input signal, consider using an ADC with differential inputs.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just run a normal ADC and accumulate the samples. Once you get a bunch of samples then you can decide what to do with the samples. You can just average them and get the DC component, or you can over sample and increase the resolution, or you can do both.

 

Delta Sigma ADCs are usually slow as sh*t, I was using a DS ADC that sampled at 200khz (single bit sample rate) data output from the ADC was around 5 khz or something like that, It was slow. It worked really nice and got superb noise rejection. Later on I ended up just using an ARM cortex device with a sample and hold ADC that ran @ ~500khz @ 12bit resolution, I did a 2 or 4x oversampling then I took the average, I might have ran them into an IIR filter somewhere. Once you have that many samples to work with, you have alot of options to process the data, much more options than using a slow DS ADC.

 

If you need super high resolution then you pretty much have to use a DS ADC, if you are after 10-14 bit resolution then as long as your sample and hold ADC is fast enough; you can get very good results.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't need super high, the ten bit ADC in the AVR is fine.  I was simply thinking out loud as to options, which in this case would be to take a bunch of readings and average them together, as the best, or most practical.

 

JIm

 

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey Mr Neil: insted of jumping all over me for making a suggestion that doesnt meet spec, how about agreeing that an analog notch filter at one or the other of the desired frequencies would in fact attenuate the unwanted signal? You Englishmen are so confrontational. Chill some like the laid back Yanks. I betcha ol Jim could build a second unit at the other freq once he got one working good at 60Hz.

 

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey Mr Gardner: instead of getting all touchy & upset when someone just asks for clarification based on on something you said, why don't you chill some and be a bit more laid back?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Standard test:

 

Are these posts "helpful"?

 

(that is all)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

do some form of 50/60hz rejection

in this case would be to take a bunch of readings and average them together, as the best, or most practical 

 

 

Averaging a large number of samples is good for removing random noise.

50/60 Hz noise injected into the signal doesn't count as "random".

Depending upon HOW the noise is present with the true signal will determine whether averaging the signal will improve the S/N ratio, or just add in an error signal.

 

Hence, the discussion about using either a hardware front end LPF, or doing it in the digital domain.

 

JC 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hence, the discussion about using either a hardware front end LPF, or doing it in the digital domain.

Yup, I was thinking of putting a 10hz low pass filter in the front end too.  I have a crude breadboard setup of the analog set up that I am playing with and laying a 120vac line cord really makes no real impact, laying just the hot line across gives the sale result. I am running my air compressor off the line when I do this.  Not a very scientific test, but as real world as I can get here .  I do see a spike when the compressor fires up, which is no big issue as the code waits a few seconds before it does anything so start up spikes will be ignored.

 

JIm

 

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

So a question is: does it really need to be able to cope with both?

Yes it does.

Would it be acceptable to have 2 product variants: one "tuned" for 60 Hz, and the other to 50 Hz?  

 

Or to have a "switch" to select between 50 & 60 Hz?

 

Or does it have to "just work" whatever the frequency?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just work would be the requirement as the end user is not going to remember to use one or the other....software or hardware.

I think the 10hz low pass will be enough. I am not running the ADC very fast and it think spikes will be more of an issue than some noise. There are TRansorbs on the inputs that will be enough.

The root of this was just to see how many different ways people have done 50/60hz rejection and to possibly make this thing a little more robust.

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Add a zero crossing detector and always measure the signal in the same place in the waveform?

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if you use a 10hz RC filter you will probably get a SNR of around 10 DB, which is really poor.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In one of my latest projects I needed 50Hz supression on a high impedance source. Although no need for 60Hz ability in MY project, I designed it to be capable for that too.

The method I used is to sample the ADC channel with the mains-frequency interference superimposed on the signal under test, with 600Hz. A timer generates that interrupt. 600Hz sampling of a 50 or 60 interference gives 12 samples for 50 Hz and 10 samples for 60 Hz. Each sample is stored and the oldest one is kicked out of the array when a new one comes available. The corrected value is the sum of the 10 (or 12) samples, divided by 10 or 12 respectively. It's important that the sampling is an even factor higher. 10 resp. 12 in this case. So sampling with 300Hz is NOT okay !

 

I understand you don want two SW versions. So I suggest you sample the mains on a different ADC channel and use that info to find out if youŕe in a 50- or 60Hz environment.

 

Important thing to keep in mind: make sure that the interference does not exceed the inputrange of the ADC ! That bit me in the beginning.

 

Using a HW filter on the input is smart for more than just one reason. A single pole at 10Hz will do fine as starter.

 

Cheers

 

Nard

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I dont understand the problem yet. I realize a filter on the input signal will work, but it can be analog, digital, all sw using a dsp. I guess it goes without mention that it must be as inexpensive as possible. The user is too stoopid to tell 50 from 60 hz, but no one has mentioned having the gizmo look for the noise and select the proper hw or sw filter. How fast does it have to respond? (Trying to calc sample rates, number of bits, response time with heavy filtering, etc) We could write an android app that reads the gps lat-long and looks up what the local mains freq is in a database. That solves the stupiduser problem.

 

Imagecraft compiler user

Last Edited: Fri. Apr 3, 2015 - 11:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

and what of using a sensor and ADC with differential input?

The power mains noise will largely cancel out - to about 50dB of common mode rejection.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I pointed out how to deal with 50Hz and 60Hz using digital filtering.

 

Uncle Bob's notch filter is nice BUT - it takes relatively good tolerance components to get a notch that is more than 20db deep. And, you would need two versions, one for 50Hz and one for 60Hz.

 

So, use the digital solution that results in a 10Hz sample rate (maybe measure at 100Hz and average 10 samples. That will give you both 60Hz and 60Hz rejection.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The usual rules apply as for any digital sampling: you *must* have a sampling frequency that is more than twice the highest frequency of interest, and you *must* provide a low-pass filter at the front end (absent fancy techniques like undersampling for direct conversion).

 

In this case, Jim has indicated 10Hz is his maximum requirement so he could sample as low as 25Hz and use an analogue filter at the front. One of the multi-stage switched filter capacitors can work very well; I've used one in a design a few months ago - oddly enough, sampling at 25Hz for a 10Hz bandwidth - with a 10Hz corner frequency and 8 filter stages, so it will be better than 48dB down by 50Hz. My choice was constrained by a need to operate at high temperature, as always, and for the accuracy of the DC signal, and there are probably others as good out there.

 

I don't recall the part number - or even the maker (I looked at so many) - but I can let you know when I return to work on Tuesday if that helps. I think Maxim or Texas; it wasn't the MF10.

 

Neil

 

p.s. band*stop* filtering in software, particularly at frequencies close to zero, is tricky: with an FIR filter it requires a lot of terms and consequent processing time. With an IIR filter it's a lot easier; two multiplies and four additions, from memory.

See this thread: https://www.avrfreaks.net/forum/t... for a notch filter and some explanation, about halfway down. Don't forget though that you *still* need the under-half-sample brick wall filter on the front end.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

2. that

That is the way to do it