Hi,
You do not have to follow the approximation given, you can do 16 bit integer arthmetic and since the CPU gives 8 bit multiply instruction, you can calculate the term more accurately with out using shortcuts.
Any how I will explain what I had in mind:
The term to be computed is 2.8*10^-6 (Rdh)^2, where Rdh is a 12 bit number.
Let us say you make the lower 8bits all to zero and take values of only the MS nibble n1 , which has an address range of 0 to F, 16 Values. You create a look up table corresponding to these 16 values of MS nibble. For example, you compute using your calculator, the value of 2.8(0X F00)^2*10^-6 =41.28D and store this value into the table corresponding to address 0XF. You do the same calculation changing 0XF to 0XE ....0X0 and get the look up table ready.
Now let us correct for the damages done by neglecting the lower 8bits to some extent.
If we consider the 12 bit number for Rdh as a sum of the MS nibble n1 and an 8bit LS byte b1, you get value of Rdh as:
Value of Rdh = (n1*1024/4 + b1)
So, (Rdh)^2 = (n1*1024/4 + b1)^2
= [(n1*1024/4 )^2 + 2 (n1*1024/4 )b1 +b1^2]
And the term in humidity calculation will be 2.8*10^-6 [(n1*1024/4 )^2 + 2 (n1*1024/4 )b1 +b1^2]
You have already computed 2.8*10^-6(n1*1024/4)^2 and kept in your table.
So the remaining error tearm is 2.8*10^-6[ 2 (n1*1024/4 )b1 +b1^2 ]
Of the error term, the max value of b1 being 256D, the max of term 2.8*10^-6*b1^2 works out to
2.8*10^-6(256)^2 = 0.18 and is coolly neglected since an error of 0.18 in humidity is not important.
Now we are left with the only error term Er = 2.8*2*256 n1b1*10^-6
If we further split b1 as n2*16 + n3 , where n2 and n3 are respectively the middle and LS nibbles of Rdh,
we get Er = 2.8*2*256 n1(n2*16 + n3 )*10^-6
Now if we consider the max value of n3 as 0X 0F and the max value of n1 as 0XF, the contribution due to n3 will be
2.8*2*256*0Fh*0Fh *10^-6 = 0.32 which is also neglected.
So you get Er = 2.8*2*256*16 n1n2*10^-6
= 2.29*n1n2*10^-2 to be precise, which you can calculate using MPY instruction of CPU.
This value of Er to be added to the byte from the 16 byte lookup table, selected based on value of n1, for each reading taken, and finally subtracted from the first term already calculated, to arrive at the % humidity value.
Regards,
Laktronics