Another way to find an average-like signal in real time, and are taking periodic readings then consider a constant \$\alpha\$ such that \$\alpha\$ << 1.
When you start up, set the output variable, call it y, to the first reliable value you get, or start with zero (but it will take longer to get to a value).
Each time you read a value, x, calculate \$ y := \alpha |x| + (1-\alpha) y\$
This is equivalent to a precision absolute value rectifier followed by a discrete-time IIR (infinite impulse response) filter with time constant \$ \tau = \frac {T_S}{\alpha}\$.
For example, if your sample time is 1msec and \$\alpha\$ = 0.001 you'll have a 1 second time constant filter.
One nice thing about this is that the storage and calculation requirements are minimal (which makes a difference in a resource-starved environment such as a PIC).
Of course you can also store a bunch of readings and make a FIR (finite impulse response) filter, and that may make sense in some situations. One advantage of the FIR filter is that there is no memory of the past after the number of readings you choose have expired- so if you have an enormous spike the hangover is not too bad.