NL2TTL,

Try these 2 routines;

This is how I read A/D converters with 10 bits resolution (0 - 1023)
The average routine is Darrel Taylor's averaging routine followed
by a simple linearization.

ReadAD: ' Read A/D converters with 10 bits resolution (0 - 1023)
ADCIN 0,AD0 'read channel 0...AN0
VALUE = AD0 >> 6
Sensor = 0
gosub Average
AD0 = VALUE
ADCIN 1,AD1 'read channel 1...AN1
VALUE = AD1 >> 6
Sensor = 1
gosub Average
AD1 = VALUE
ADCIN 2,AD2 'read channel 2...AN2
VALUE = AD2 >> 6
Sensor = 2
gosub Average
AD2 = VALUE
ADCIN 3,AD3 'read channel 3...AN3
VALUE = AD3 >> 6
Sensor = 3
gosub Average
AD3 = VALUE
ADCIN 4,AD4 'read channel 3...AN4
VALUE = AD4 >> 6
Sensor = 4
gosub Average
AD4 = VALUE
Return

Average: ' Average Analog values -=-=-=-=-=-=-=-=-=-=
IF Value = ADavg[Sensor] Then NoChange
IF ABS (Value - ADavg[Sensor]) > FAspread OR Value < AvgCount Then FastAvg
IF ABS (Value - ADavg[Sensor]) < AvgCount Then RealClose
ADavg[Sensor] = ADavg[Sensor] - (ADavg[Sensor]/AvgCount)
ADavg[Sensor] = ADavg[Sensor] + (Value/AvgCount)
GoTo AVGok
FastAvg:
ADavg[Sensor] = Value
GoTo AVGok
RealClose:
ADavg[Sensor] = ADavg[Sensor] - (ADavg[Sensor]/(AvgCount/4))
ADavg[Sensor] = ADavg[Sensor] + (Value/(AvgCount/4))
AVGok:
Value = ADavg[Sensor] ' Put Average back into Value
NoChange:
if AD0 >= 435 then RA = 66 'thermistor linearization
if AD0 >= 446 then RA = 67
if AD0 >= 450 then RA = 68
if AD0 >= 456 then RA = 69
if AD0 >= 461 then RA = 70
if AD0 >= 477 then RA = 71
if AD0 >= 473 then RA = 72
if AD0 >= 479 then RA = 73
if AD0 >= 486 then RA = 74
if AD0 >= 492 then RA = 75
if AD0 >= 499 then RA = 76
if AD0 >= 506 then RA = 77
if AD0 >= 513 then RA = 78
if AD0 >= 519 then RA = 79
if AD0 >= 526 then RA = 80
if AD0 >= 529 then RA = 81
if AD0 >= 535 then RA = 82
if AD0 >= 544 then RA = 83
if AD0 >= 548 then RA = 84
if AD0 >= 552 then RA = 85
if AD0 <= 438 then RA = 59
if AD0 >= 562 then RA = 58
Return



This is how I determine my fan speed. In my case the minimum Fan speed is
60%.

IF RA <= SETPOINT Then cbs
ERROR = (RA - Setpoint )
IF ERROR <= 2 then FANSPEED = 153 '60%
IF ERROR >= 3 then FANSPEED = 178 '70%
IF ERROR >= 5 then FANSPEED = 204 '80%
IF ERROR >= 7 then FANSPEED = 229 '90%
IF ERROR >= 9 then FANSPEED = 255 '100%
CASE 2
cbs: FANSPEED = 153 ' manual spd 1
CASE 3
FANSPEED = 204
case 4
FANSPEED = 255
end select
IF FANSPEED > SPD + 50 THEN SPD = SPD + 2 'softstart or slowly
IF FANSPEED > SPD THEN SPD = SPD + 1 'change speed
'IF FANSPEED < SPD + 50 THEN SPD = SPD - 10
IF FANSPEED < SPD THEN SPD = SPD - 1
hpwm 2,SPD,32767 ' PWM 32 KHz
return

I hope this helps get you started.

Mark