Page 1 of 1

Moving Average

Posted: Tue Sep 28, 2021 7:36 pm
by AbhijitR
Hello!

I am trying to stable the reading of ADC value, is it possible to put some light if someone has already done in the past, the ADC is of 18Bit how to do the calculation using Moving Average method. I read very few post on this topic, most of them are from V4, it will be great if someone could share a working chart.

Thank you.

Abhi

Re: Moving Average

Posted: Tue Sep 28, 2021 9:16 pm
by medelec35
Hi Abhi.
I have just put a moving average demo together for you.
Its only going fairly slow because its a demo
You can remove LCD macros and delay from MovingAverage User Macro.

Re: Moving Average

Posted: Wed Sep 29, 2021 9:18 am
by AbhijitR
Hello! Martin
good morning

So nice of you to post the example, thank you.

May i request you to answer one doubt, i notice the ADC value receiving from the pot is 1023 as the resolution is of 10Bit in the example chip, on contrary i am using the component MCP3421 which has got 18Bit resolution, in that case what are the necessary changes i need to do, is it to change the variable or the calculation will also change.

Honestly, i tried to learn/understand Jan Lichtenbelt chart too regarding the same topic but i did not understand how i can implement that in my case. I notice one thing, kindly correct me if i am wrong, the ADC value which is received from the pot 0-1023 is scaled to 0-32768, calculated and then scale back to 0-1023, but in my case i am using 1/4th part of the ADC count from the MCP3421 (this ADC receives 0-2.048V analog signal and output 0-131071 count) which is 32767 as i am feeding on 512mV as analog signal, this configuration works well for getting the count from the ADC.

My doubt is if i am already receiving 0-32767 count from the ADC then in that case is the scaling necessary, if not then how to remove that, i tried doing but without success.

Thank you, hear you soon.

Abhi

Re: Moving Average

Posted: Wed Sep 29, 2021 10:36 am
by QMESAR
but in my case i am using 1/4th part of the ADC count from the MCP3421 (this ADC receives 0-2.048V analog signal and output 0-131071 count) which is 32767 as i am feeding on 512mV as analog signal, this configuration works well for getting the count from the ADC.
Abhi.

if you only use 0-512mV then use a PGA gain of 4(4x512mV = 2.048) and set the Sample rate to 2 (which is 16 bit)then you can use the example directly.if you want to use the 18bit then use a PGA gain again of 4 and use a longs to do the running avaregae 18 bits does not fit in 16 bit variables :D

Re: Moving Average

Posted: Wed Sep 29, 2021 11:35 am
by medelec35
Hi Abhi.
I have made a small adjustment so it should work from 0 to 32767.
On the higher values the count is out slightly
I'm not that great with maths so I used Jan's example and changed it slightly.

Re: Moving Average

Posted: Wed Sep 29, 2021 12:43 pm
by AbhijitR
Hello! Martin Hello! Peter
good afternoon

Kindly excuse to speak my mind but what a profound feeling of friendship, thank you both very much for your answers. I check both the options and keep posted with the result.

Thank you again.

Abhi

Re: Moving Average

Posted: Fri Oct 01, 2021 1:40 pm
by AbhijitR
Hello! Martin

Once again thank you for your help for the moving average example, but to be honest with you i used your other example again (Analog Filter) it works fantastic for this application, thank you for that example too.

Hello! Peter

As you said i have changed all the variables to Long and now everything works flawless, ranging the count from 0-32767 to 0-131071 gave me a big gap to adjust the error using Martin's Analog filter.

Thank you once again to both of you to help me, cheers...

Abhi