thanks guy's
I was going for the following
636 was the running total of 10 samples minus the highest and lowest. That left 8 samples.
I therefore wanted to divide 636 by to get 79.5.
I ended up multiplying by 50 and diving by 4, then handle the digits either side of the decimal place (see example) it's work in progress, but welcome any pointers
Code:
temp_val[1] = 100 ; real tempeture 10.0c
temp_val[2] = 115 ; 11.5c
temp_val[3] = 122 ; 12c etc...
temp_val[4] = 139
temp_val[5] = 150
temp_val[6] = 130
temp_val[7] = 80
temp_val[8] = 100
temp_val[9] = 115
temp_val[10] = 252
' total = 1301
' lowest = 8.0c
' highest = 25.2c
' middle 8 samples = 971
' average of the 8 sample = 121.1375 or 12.137c
;----[Main Program]---------------------------------------------------------
mainloop:
'index = 0
'index2 = 0
temp1[1] = 0
temp1[2] = 0
temp1[3] = 0
for index = 1 to 3 step 1 ; Take 10 sampels from 3 sensors
For index2 = 1 to 10 step 1 ; Take 10 reading
IF index2 = 1 THEN
temp_val_lo[index] = temp_val[1] ; Set initial lowest reading to first reading
temp_val_hi[index] = temp_val[1] ; Set initial highest reading to first reading
endif
LCDOUT $fe,1,"Sensor ",DEC index, " Data ",DEC index2
if temp_val[index2] <= temp_val_lo[index] then ; If readling lower than lowest
temp_val_lo[index] = temp_val[index2] ; Update lowest
elseif temp_val[index2] => temp_val_hi[index] then ; If reading higher than highest
temp_val_hi[index] = temp_val[index2] ; Update highest
ENDIF ; Else reading is not highest or lowest and....
temp1[index] = temp1[index] + temp_val[index2] ; Add reading to running total
next index2 ; Update next sample
temp1[index] = temp1[index] - temp_val_hi[index] ; Subtract the highest reading
temp1[index] = temp1[index] - temp_val_lo[index] ; Subtract the lowest reading
temp1[index] = (temp1[index] * 50)/4 ; Get rid of the decimal places
LCDOUT $FE,1, "Sensor = ",DEC index
LCDOUT $FE, $C0,"Temp = ",DEC temp1[index] DIG 4, DEC temp1[index] DIG 3,".", DEC temp1[index] dig 2, dec temp1[index] dig 1, dec temp1[index] Dig 0
PAUSE 2000
next index ; update next sensor
PAUse 5000
goto mainloop
End
Bookmarks