In a different application I used a "weighted Average" where no one sample could mangle the running average.
This is the regurgitated conversion to PBP:

I initialize the values and add new value to the stack and subtract off the old average, giving the new value 1/weight of effect

I leave the running average in A2D counts to avoid rounding
Must watch (Max value * number of samples) < 65000


Weight var byte
WeightedAve var word
Ave var word
WeightedCounts
NewAve var word
Count var word

AveragingComplete var word

Incoming var word ‘incoming value from a2d
WeightedCounts=0
Weight = 100
AveragingComplete = 0
Ave=0

If Count=0 then WeightedCounts= incoming* Weight
If Count=0 then Ave= incoming

If Count < Weight then Count = Count + 1
NewAve =(incoming+ WeightedCounts-Ave
WeightedCounts= NewAve
Ave= WeightedCounts/ Weight
If Count = Weight then AveragingComplete = 1
If Count = Weight then Display “Weighted Average” ‘lcd routine
If Count < Weight then Display “building average” ‘lcd routine