Hello all,
I'm trying to calculate the the moving average of a word size variable. The formula I'm using is listed below and is standard as far as I can tell. New values of watts are added to the average when a counter is incremented by 1 in my program.
Code:
  wattsAvg = (wattsAvg*counter + watts)/(counter + 1) 'moving average of watts
The results obtained are correct as as long as the numbers stay within word size limits. However, that is not the case as my numbers can range as follows:
counter : 0 to 400
watts : up to 7500 max

I think the problem would be solved with longs, but these require an 18F part. I'm using a 16F1823 as I need very small size device. I tried DIV32 as follows;
Code:
  dummy = wattsAvg*counter + watts
  wattsAvg = div32 (counter + 1)
This does not work. Apparently you cannot mix multiplication and addition on the dummy line. The result is always zero.

Grateful for any ideas.