Hello Benj,All,
I would like, for reasons of precision, to be able to memorize in the EEPROM for example a value U = 4.9542
I tried by creating a 16-bit shift variable, with a variable U as Integer
MSB = U >> 8
LSB = U
=> EEVAL = (MSB << + LSB
eeprom1::write(0,MSB)
eeprom1::write(1,LSB)
It works but on 10bit only and the accuracy is not enough.
I can not either multiply 4.9542 * 10000 and recreate the shift variable, because the variable is type of Float and I would not get as a result 4.9542 * 10000 = 40000 (if I'm not mistaken).
Please, how can I do? Do you have an example ?
Thank you in advance for your replies
Write float value in eeprom
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Write float value in eeprom
Hello,
You could multiply out the value first using floating point maths.
Other ways include converting the float to a string and storing the string or splitting the float up into an array of 4 bytes using a union and then recombining directly into a float. The latter method is C only and won't simulate.
You could multiply out the value first using floating point maths.
This is correct. However...4.9542 * 10000 = 40000
Which you can then copy to your integer variable.4.9542 * 10000.0 = 49542.0
Other ways include converting the float to a string and storing the string or splitting the float up into an array of 4 bytes using a union and then recombining directly into a float. The latter method is C only and won't simulate.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Write float value in eeprom
Thank you Benj,
I will try the first solution.
As for the second that you propose, I tried in C but I was not successful, during the compilation I got a lot of errors. Do you have an example (under the elbow).
Luc
I will try the first solution.
As for the second that you propose, I tried in C but I was not successful, during the compilation I got a lot of errors. Do you have an example (under the elbow).
Luc
-
- Posts: 1
- Joined: Tue Feb 26, 2019 6:27 am
- Been thanked: 1 time
-
- Posts: 1
- Joined: Tue Apr 30, 2019 10:28 am
- Contact:
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Write float value in eeprom
In Flowcode 8.1 there is a new component available under Data -> Storage called Type Conversions.
This allows you to convert between different types of variable e.g. a float can be converted into 2 unsigned ints or 4 bytes and visa versa.
This allows you to convert between different types of variable e.g. a float can be converted into 2 unsigned ints or 4 bytes and visa versa.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel