PDA

View Full Version : adc averaging readings



amgen
- 20th June 2006, 03:38
hello,
for a alternator regulator using 12f683 pwm, i want to smooth a/d readings by taking 3 readings and discard the high and low reading to make next pwm calc. I'm trying to keep math calculations from slowing down process too much. any fast way to check 3 readings and discard high and low reading?

also working on a self tuning PID. seems like the micro and program could tune itself to simply reduce/increase P,I or D to stop or set overshoot .am i missing too many brain cells?

don
american generator

paul borgmeier
- 20th June 2006, 08:02
any fast way to check 3 readings and discard high and low reading?

X1 VAR word ;1st data point
X2 VAR word ; 2nd data point
X3 VAR word ; 3rd data point
Xtemp VAR word ; temp variable

;******************
Gosub X2X1Compare

If X3 < X2 THEN ; swap if true
Xtemp = X2
X2 = X3
X3 = Xtemp
ENDIF

Gosub X2X1Compare

X2 is now your keep value ; <- here is your answer

END
;******************
X2X1Compare:
If X2 < X1 THEN ; swap if true
Xtemp = X1
X1 = X2
X2 = Xtemp
ENDIF
Return
;******************
However, it is would be much easier and computationally faster to sample 4 values, add them together, and divide by 4 (using shift right)

Xtemp = X1+X2+X3+X4
Xtemp = Xtemp >> 2 ; <- here is your answer
Paul Borgmeier
Salt Lake City, Utah
USA

amgen
- 21st June 2006, 00:57
Paul,
Thankyou for your suggestion to take 4 readings etc. I will use that routine. Its always better the simpler.
don
american generator