Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

filtering adc samples using stm32

Status
Not open for further replies.

lowpowermcu

Junior Member level 2
Joined
Aug 8, 2012
Messages
20
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,425
Hi all,

I am acquiring adc voltage using stm32 device and after 1000 samples I am doing the mean value but I have found that this is not sufficient in my case (the value (average) I got is not stable) I thought to increase the number of samples (size of buffer) but I face RAM size issue so I want to know is there some other method to have a stable value other than averaging ?

MCU Lüfter
 

have you tried a running average? also zeroing the least significant bits of the ADC value?
have you looked at your signal with an oscilloscope? have you a lot of noise or could you be aliasing?
 

Instead of storing the samples, why don't you sum the Sample using a counter and then divide per the value of the counter ? If you want to calculate the mean of 5000 samples, you use a variable used to sum each sample at the sampling rate and then (you count the samples with a counter) and then you divide the sum per the value of your counter.
 

Hi guetguet,

because I am using the ARM library, I'll try to test my code as you said and I'll keep you informed.
@horace I tested with zeroing the LSB but w/o success, I didn't find in ARM DSP library running (moving) average algorithm.

MCU Lüfter
 

I read this somewhere and saved it. How to implement a simple single pole digital filter. It works great and I now use it all the time.

Many systems use an ADC to sample analog data that temperature and pressure sensors produce.
Sometimes, system noise or other factors cause the otherwise slowly fluctuating data to "jump around." To reduce higher frequency noise, designers often install an analog RC (resistor-capacitor) lowpass filter between the sensor and the analog-to-digital-conversion stage. However, this approach is not always ideal or practical. A long time constant of minutes would require very large values for R and C.
An analog RC lowpass filter's turnover frequency or cutoff frequency (in hertz), is determined by the time constant of R in Ohms and C in Farads.
Frequ. = 1 / (2 * Pi * R * C).

As an alternative, you can clean up noisy signals that remain within the ADC's linear range by using the digital equivalent of an analog RC lowpass filter.
The filter's software comprises only two lines of C code:

LPOUT = LPACC / K

where the output value of the filter is LPACC divided by a constant, and

LPACC = LPACC + LPIN - LPOUT

where you add the difference between input and output to update LPACC.
You specify all variables as integers.
Each time the analog-to-digital conversion acquires a new input sample, LPIN, the software produces an output value, LPOUT, which comprises a lowpass-filtered version of the input samples.
Calculate the value of the constant, K, based on the sampling rate of the system and the desired time constant for the filter as follows:

K = T × SPS

where K > 1, and SPS is the system's sampling rate.

For example, for a system-sampling rate of 200 samples/sec and a desired time constant of 30 sec, the constant K would equal 6000 samples.
Applying a step change to the routine's input requires 6000 samples to reach approximately 63% of its final value at the output.

The lowpass accumulator, LPACC, can grow large for large time constants and large input values. It can grow as large as K times the largest possible LPIN value. Under these conditions, you need to make sure that LPACC does not overflow, and you may need to specify a larger data type to contain LPACC.
To avoid a long settling time during start-up, before the start of the sampling loop, you can initialize LPACC to a value of K times the current input value.
 

So try to change a little the code of ARM, it will be pretty easy :razz:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top