Ok, here's one way to do it.
The general formula would be ....
result = (adc_in - CalLO)*Range/(CalHI-CalLO)
.... where
adc_in = input from ADconverter
Range = Maximum load
CalLO = adc_in when load is zero
CalHI = adc_in when load is "Range"
You could calculate and "hardcode" the last two, but the best solution would be to make a small calibrationroutine that gathers the readings. I'll use 0.44v as zero load and 4.99v at maximum load(300lbs).
Code:
Range CON 300
adc_in VAR WORD
CalLO VAR WORD
CalHI VAR WORD
div_val VAR WORD
result VAR WORD
dummy VAR WORD
CalLO = 90 ' calculated calibrationvalue (0.44/5*1024)
CalHI = 1022 ' calculated calibrationvalue (4.99/5*1024)
div_val = CalHI - CalLO
dummy = (adc_in - CalLO) * Range
result = DIV32 div_val
If you want rounding you could do .....
Code:
Range CON 3000
adc_in VAR WORD
CalLO VAR WORD
CalHI VAR WORD
div_val VAR WORD
result VAR WORD
dummy VAR WORD
CalLO = 90 ' calculated calibrationvalue (0.44/5*1024)
CalHI = 1022 ' calculated calibrationvalue (4.99/5*1024)
div_val = CalHI - CalLO
dummy = (adc_in - CalLO) * Range
result = DIV32 div_val
result = (result + 5) / 10 'rounded result
/Ingvar
Bookmarks