Just thinking out loud. At first glance, it looks like an overflow is breaking the average.
You are averaging 1000 samples of a 10bit value. Assuming the value you want to reach as in your text is 25.0(or 250 counts) in 1000 iterations, the variable for tempsum should be at lease 250x1000 = 250000 big. or, it should be bigger than a word sized variable (max 65535)
You could try an alternate averaging technique called moving average which works continuously per sample and is not delayed by waiting for 1000 readings.
Vout = (Vout * 3 + Adcin )/4
Here, you are continuously averaging the readings like you would do 4 of them together. You could change the formula to any value you want to speed up / slow down the averaging. The numbers should always be (Vout * (n-1) + adc)/n
Hope that helps




Bookmarks