I usually avoid use of floating point on a processor that does not have native support for it. It is an intensive computation and in most cases will eat up a sizeable amount of time to achieve the same result that you could with clever integer manipulations. In your case, you seem pretty clear you need fixed point arithmetic and so it is easier. You may need 32 bit integers to handle larger numbers.
In your case, the equations you show boil down to these
Assuming Temp is the input temperature read via the ADC and you want to calibrate the reading by temp*100/calc_adjust
Temp = Temp *100 ' max temp = 65535/100 ($FFFF hex)
Temp = Temp / Cook_Adjust ' Divide and keep the integer part of result.
Assuming you want a 0.1 deg resolution, I would do this (keep in mind the largest value that Temp can hold. Temp*1000 will define the limit of temperature going into the routine)
Temp = (Temp*1000)/Cook_Adjust (max input temp is now 65 since 65*1000 approximately fills the 16b integer)
You could also do this
Temp = (Temp*100) / (Cook_Adjust / 10) (max input temp is 650. However, cook_adjust should be multiples of 10 to impact the calculations)
Now, convert to F
Temp = Temp + (Temp << 3) ' mul by 9 x + 8*x = 9x
Temp = Temp / 5 ' div by 5
Temp = Temp + (32*10) ' add 32 with 1 decimal accounted for
and display it by splitting the value thus
Display Temp / 10, ".", Temp MOD 10
You need to specify your input range to make this technique practical for you.
Bookmarks