Hello Jonny,
So I have tried a few things:
I have created a LUT such as:
Code: Select all
const double B_TERMS[B_COUNT][B_MAX_SUBCOUNT][TERM_COUNT]=
{
{
{280.0,3.199,84334.662},
{102.0,5.422,5507.553},
{80,3.88,5223.69},
{44,3.7,2352.87},
{32,4,1577.34}
},
{
{9,3.9,5507.55},
{6,1.73,5223.69}
}
};
Then I created a macro with a C code to get the values from the LUT and display this on an LCD. I have tried displaying it with a gcvt function, and with float to integer macro, just to make sure both are the same and gcvt function is not introducing some errors. But the results were the same. For example i was trying to display the value 5507.55 but I was receiving value of 5507.5498. Then I have tried storing a the same value but multiplied by 10pow6 (5507550000) and later divide the value by the same 10pow6 to see if this made any changes. Unfortunately I received a value of 5507.5502 . I remember Sean mentioned the possibility of rounding errors in his article about the lookup tables, here is the quote:
Hello,
Yes, it is possible to change the array data type to suit the range of the data values being stored. The Flowcode variables used to handle the data (including the table reader macro return variable) will also need to be changed to match the selected data type.
The C data types that are directly compatible with Flowcode depend on the version of Flowcode being used. In the case of Flowcode for ARM, a 'Float' variable is compatible with a C 'double' variable.
The use of floating point variables introduces the possibility of rounding errors, but some of your example values are too large for the 'int' option.
So the question stands, what to do to avoid this? Any Ideas?
I have also added just an example the amount of error I get due to this imperfection in my calculations on the ARM.
Best regards,
Mantas
Science is my true religion.