Average of samples ADC

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Is there a way to select a number of samples taken from the ADC and than take the average of the samples to get the final result, only using hardware.

So for Example; I only want to get a result from the ADC after he took 10 samples and averaged those.
It must be done with the hardware, so writing 10 result in an array and than taking the average isn't what I'm looking for.

BTW, I am working with the XMC4500

Thanks in advice
0 Likes
8 Replies
Not applicable
Hi,

I'm afraid it is not possible for your case (average 10 samples).

Best regards,
Sophia
0 Likes
AndreasG
Employee
Employee
10 replies posted 5 replies posted Welcome!
Just to note, as Sophia says, an average over 10 samples is not possible.
But there is an option to accumulate up to 4 samples.
You can find more details on this in the sub-chapter "Data Modification" of the ADC chapter in the XMC reference manual. As you can see there, apart from the "Data Reduction Mode" that describes the accumulation, it offers also a FIR, IIR and a difference mode.
0 Likes
Not applicable
Hi Sophia and AndreasG,

Thank for your reply. I used the Data Modification. Is it possible to only output the 4th result and than divide it by 4? Because now it gives me an output like Sample1, Sample1 + 2, sample 1+ 2 + 3, Sample 1 + 2 +3 + 4, sample 1,.. and so on. But I only want to get Sample 1+2+3+4. Do I have the change something in the program for that? Now I only changed kDataModification to 0x03.

Thanks in advice
0 Likes
Not applicable
Hi,

Yes, the result event can be generated only if the accumulation is complete. (refer to Chapter 19.8.5 Result Event Generation of "xmc4500_rm_v1.5_2014_07")
You can observe the effect using "ADC002_Example1":
Double-click ADCCH001 App to open the UI Editor --> Select "Accumulate 4 Results" for Data Modification in "Result configuration" tab --> Generate Code then Compile...
Do remember to do "Apps Migration" 1st (if the Apps are not latest) before doing editing of the Apps.

Best regards,
Sophia
0 Likes
Not applicable
Hi Sophia,

Thanks for the reply.This works. But are you sure that this only outputs the accumulating of the 4 results without give first an result of the sum of 1, 2 and 3 samples? Because this is the case in DAVE 4. In Dave3 it's seems that it is only the result of the accumulating of the 4 results (Like I want it) but I'm not 100% sure.

Thanks for your help!
0 Likes
Not applicable
Hi,

Are you referring to ADC_MEASUREMENT APP in DAVE v4?

Best regards,
Sophia
0 Likes
Not applicable
Yes I am

Thanks in advance
0 Likes
Not applicable
Hi,

I think you observe this (result of the sum of 1, 2 and 3 samples) in the debug mode? What you have observed is caused by the debugger.
You can use the following code to test (place the breakpoint at i=0). You could find that the result event is triggered at end of every 4th accumulation.


void Adc_ResultEvt_Handler(void)
{
static uint16_t result[50];
static uint16_t i=0;

result=VADC_G0->RES[4] & VADC_G_RES_RESULT_Msk;
i++;
if(i==50)
{
i=0;
}

}

Best regards,
Sophia
0 Likes