5 posts / 0 new
Author
Message

I'm using an atmega328p with 2 ADC input signals, one to monitor the battery and one current sense for my DC motor in order to detect jams. The datasheet says that frequencies above f_adc/2 should be removed. Since I'm running at 8MHz with a prescaler of 128, I'd need to cutoff above roughly 30kHz. I'm doing this using an LC filter with L=56uH and C=470nF. Using an online calculator this should have the correct cutoff frequency. While reading online there are a few things I became confused about.

1. In this post it says that f_adc is the sample rate instead of ADC clock, since it doesn't even get sampled at 1Hz, it seems like this would lead to very large inductance/capacitance values?
2. In the same thread it is often mentioned that no filter is needed except if it is a noisy environment. Given the fact that I'm using a DC motor, it seems that this would be the case?
3. In this post it is said that noise problems are generally part of another problem and, other than in the case of long cables, is probably not solved by filtering adc signals.

Given this information, I'm not exactly sure what reasoning to use to calculate the values for the LC filter, or that I even need one, or maybe just a cap or RC filter? Any clarification would be greatly appreciated.

Here is 'the schematic in case it helps clarify things.

The Shannon-Nyquist Theory deals with digital sampling of signals.

It is important with sampling repetitive signals with the intention of being able to "reproduce" the original signal.

If you were sampling a 1 KHz sin wave and want to reproduce it with a DAC you would want to sample the input sin wave at > twice the highest frequency component within the input signal of interest, (i.e. 2 * 1 KHz, or sample at > 2 K samples / second).

That said, the above doesn't really apply, (much / directly) to what you are doing.

The battery is a steady state DC voltage.

The resistor divider and cap is perfect for that.

The frequency of interest for the current sense is how fast the current is changing, is it pretty steady state, is it varying a lot, (quickly).

The sampling rate impacts your ability to measure rapid changes in the current an not miss them.

So, generally, motors are mechanical systems can change "slowly", from an electronics perspective.

You might think of it as switching state fro running / stalled / running / stalled / running / stalled, etc., as a periodic wave form for the two states the system can be in.

Not to useful, but the point is your basically looking for the transition between to states, and not a periodic waveform.

And for that the Shannon-Nyquist theorem isn't really pertinent.

You might decide to set a Timer/Counter to interrupt once every 1 mSec and measure the motor's current.

Actually, you might have the micro read the last reading, and trigger the next reading, so you are always 1 mSec behind...

Given this, you want a filter on the input to remove the higher frequency spikes and noise on the current sense signal.

But you would want to be sampling at twice the highest frequency in the input.

So, following the above, you could have a LPF of 500 Hz and sample at 1 K samples / second.

Obviously the lower the LPF cutoff, the slower is the response of the input signal to sudden changes in current.

So, you might deviate from the above an go with a higher cutoff frequency, aimed at just eliminating the higher freq noise and spikes on the input signal.

What yo do depends a lot upon how quickly the system changes state, (i.e. running normally to stalled).

How fast your control loop is running.

etc.

Putting an O'scope on the signal will tell you a lot about the noise present that you want to filter out.

Lastly, nothing wrong with using an LC filter.

The AVcc pin should have an LC filter powering the pin from the Vcc rail.

But, for filtering the input signals I would have probably investigated an RC LPF first.

Finally, the impedance of the source driving the ADC input on the micro should be less than 10K ohms.

Therefore, for real systems, one might want an op-amp filter driving the ADC input.

The op-amp filter has a low impedance output, good for driving the ADC.

A carefully designed input filter might not require the op-amp.

JC

Edit:  Add another comment or two.

Last Edited: Wed. Jan 27, 2016 - 01:15 AM

The battery is a steady state DC voltage.

The resistor divider and cap is perfect for that.

Do you suggest with this that I remove L2 and C8 and just keep C2 (close to the MCU) then?

The frequency of interest for the current sense is how fast the current is changing, is it pretty steady state, is it varying a lot, (quickly).

The sampling rate impacts your ability to measure rapid changes in the current an not miss them.

Wouldn't it make sense then to log the current sense data and then look at the Fourier transform in order to determine cutoff frequency and sample rate?

Lastly, nothing wrong with using an LC filter.

The AVcc pin should have an LC filter powering the pin from the Vcc rail.

But, for filtering the input signals I would have probably investigated an RC LPF first.

An RC seems like a good solution! While it will only drop off at 20db/decade as opposed to 40db/decade for an LC filter after the cutoff frequency, It seems that it is a lot easier to get low cutoff frequency with an RC than with an LC. The cutoff frequency f ~ 1/RC in the case of RC filter and f ~ 1/sqrt(LC) in the case of an LC filter. It is not only a lot easier (and cheaper) to get large values for R than for L, but it is also inversely proportional as opposed to the being proportional to the inverse of the square root. In addition, an LC seems somewhat dangerous (in theory) without a resistance since at the resonance frequency it looks like it would amplify noise instead of suppress it but I'm guessing in practice there is always a resistance that makes for damping. Thanks for the suggestion!

I wrote that while I was 1/2 asleep.

Bottom line, you really are not sampling a repetative signal with a need to reproduce taht signal, so SNT doesn't directly apply.

Your signal, motor off, motor running, motor stalled, is essentially 3 states.

Sample the current a few times to take an average, and then see which level it falls in.

The filter is for removing higher freq spike and motor and other noise, all of which is well above the cut off freq for a LPF for monitoring the motor status.

Tell me again the purpose of the Vcc monitor feeding pin 24?

If Vcc comes out of the voltage regulator, and powers the micro, then it doesn't buy you much.

The V Batt monitor tells you if the battery supply is falling and approaching the minimum input voltage for the voltage regulator.

If so, then you ought to do something, eMail the Battery replacement human, shut off the load, etc.

Waiting for the (brief) window then the regulator is out of spec, and not providing a full Vcc, because of a low Vbatt input is a bit late in the game, and the operation of the regulator and the micro is all a bit suspect at that point.

Additionally, you should consider enabling the Brown Out Detector on the micro.

The Fuses set the voltage level, and enable it.

If Vcc drops under that voltage then the micro is held in reset so that it can't act erratically.

JC