You may not need more than a few points on the curve (depending on how much error you can tolerate) and linear interpolation to retrieve the values. I normally use this technique to curve-fit temperature sensors to real world readings. This is how it works in an example (ADC is assumed 8 bit)
Code:
array of array of
Real values measured values
0 5
25 40
100 150
175 180
200 225
Pseudo code
' Enter with ADC_reading in the range of 5-225(meas values)
' return with Actual_reading in the range 0-200
Linearize:
for cnt = 4 to 1 step -1 ' I assume array to be starting at 0 (like in C)
if ADC_reading < Meas_Value[cnt] then
m1 = Meas_Value[cnt-1]
m2 = Meas_Value[cnt]
r1 = Real_Value[cnt-1]
r2 = Real_Value[cnt]
'interpolate the adc reading between m1, m2 and r1, r2 to get the actual value
' multiply first using 16 bit integers to ensure the result is within 16bits
Actual = [(Adc_reading - m1) * (r2-r1)] / (m2-m1) + r1
return
endif
next
return 0 ' unsuccessful in finding a match
Hope that helps
Bookmarks