How does the averaging modes work on adc?

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

cross mob
Anonymous
Not applicable

Averaging Mode
This parameter sets how the averaging mode operates. If the accumulate option is selected,
each ADC result is added to the sum and allowed to grow until the sum attempts to outgrow a 16
bit value, at which point it is truncated. If the Fixed Resolution mode is selected, the LSb is
truncated so that the value does not grow beyond the maximum value for the given resolution.

   

Can someone give me an example of these 2 options?

0 Likes
17 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

OK, just to make some initial assumptions: the alternate ADC resolution is configured to 10 bits (so we have a range of 0..1023), and the number of averaged samples is 256. Also, for the sake of easy calculation, assume that all samples read 512.

   

Then what happens is (when a channel is configured to use averaging): 256 samples are taken, and their values are added together.

   

In 'accumulate mode' this will be 256 times the value 512. This means that at the 126th sample, the result will overflow to 0 (128*512=65536), the same happens with the last sample (so the final result is 0).

   

In 'fixed resolution' mode, the 8 LSBs are truncated, and only the two leftmost bits are added (which happens to be '2' in our case). So we get a result of 256*2=512

   

Now assume we average only 64 samples. In the 'accumulate' case we get a result of 64*512=32768, which we would need to divide by 64 again. In 'fixed resolution' mode, the 6 leftmost bits are truncated, so we get a result of 64*8=512.

   

Now the results will be a little bit different when the samples all have different values. Then the 'accumulate' mode with subsequent division might deliver more accurate results, since the LSBs are taken into account. But one needs to be careful not to run into an overflow situation (so the resolution and the number of samples should be checked).

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

If you go here -

   

 

   

    

   

          http://www.cypress.com/?app=search&searchType=advanced&keyword=&rtID=117&id=4749

   

 

   

there is an Architecture TRM manual you can download, and an extensive chapter

   

in the analog section on the SAR including its avergaing modes and the registers

   

that control them.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Maybe I am not reading this correctly but I think there is not any

   

situation where overflow can occur from averaging. From TRM -

   

 

   

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Paste did not work, see attached.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
EvPa_264126
Level 7
Level 7
500 replies posted 250 replies posted 100 likes received

   

Something I do not see the difference (((

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

One mode will give you the sum of n samples,

   

the other mode truly returns the average which is (sum of n Samples) / n

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

The second one is more like

   

sum of n (Samples / n)

   

where the /n part is done by right-shifting the values before the addition. So this looses some precision.

0 Likes
lock attach
Attachments are accessible only for community members.
EvPa_264126
Level 7
Level 7
500 replies posted 250 replies posted 100 likes received

Bob, I think have to make your way to the averaging result (GlidingAVRG)

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Hmmm, GLIDING average with k samples is more like

   

 

   

AVn+1 = (AVn * (k-1) + Sample) / k

   

 

   

Do you agree?

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Some considerations and alternatives -

   

 

   

    

   

          http://www.chem.uoa.gr/applets/appletsmooth/appl_smooth2.html

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

My security shields warned me of an object on that site.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
EvPa_264126
Level 7
Level 7
500 replies posted 250 replies posted 100 likes received

No, Bob. For UintXX  present hysteresis. I'll leave this task to the next.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Yes the site has a Java applet running.

   

 

   

My shields don't squawk, mine are bigger than yours

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Attached a paper, discussion, of averaging filters and their

   

impact on roundoff and computational requirements.

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Yes, the averaging math....

   

I have learned a simplification when calculating a gliding average that works astonishing well:

   

As shown in Dana's links the next average is calculated by subtracting one element and adding the newest. This way you are obliged to maintain an array of k element values when calculating a gliding k average. A space and code-saving approximation is to use the last calculated average for the value of the element to subtract. So the whole algorithm shortens to my above given formula without the need of maintaining an element array.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Project written and attached.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

For low k in Bobs design the error rises. You can establish

   

that by taking the limit of the function as k approaches some

   

value. Choice of algroithim all depends on accuracy, latency,

   

and of course HW & SW cycles needed.

   

 

   

The traditional running average of a set of samples has its

   

own issues, essentially the convolution of a window onto the

   

dataset. You could always run some tests with a noise source

   

generated by PSOC.

   

 

   

Regards, Dana.

0 Likes