I need to convert a float32 value to an unsined integer value and the also the opposite function using F28335.
Is there any Uint16_2_Float32 function?
How can I do that?
Regards
Glória
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I need to convert a float32 value to an unsined integer value and the also the opposite function using F28335.
Is there any Uint16_2_Float32 function?
How can I do that?
Regards
Glória
Like this:
float f = 3.14;
unsigned int ui = f;
float f2 = ui;
The conversion is done by library functions.
As an additional note:
* if your integer value is an IQ number then you can use the IQmath library to convert in C.
* If you're writing in assembly you can use the FPU conversion instructions and scale - ie
UI16TOF32 R0H, @_AdcMirror.ADCRESULT0
MPYF32 R0H, R0H, #(1.0/scalefactor)
-Lori
Lori,
Why would you have to do the scaling ( #1.0/scalefactor) )? I was hoping the UI16TOF32 would generate a F32 that was ~ equal to the UI16 value that went into the assembly. Would it be possible to get an example of a C-Callable assembly function that did conversion from UI16->F32 and back again?
Thanks
David,
David Harding said:Lori,
Why would you have to do the scaling ( #1.0/scalefactor) )? I was hoping the UI16TOF32 would generate a F32 that was ~ equal to the UI16 value that went into the assembly.
You don't have to scale. It really depends on what you want to do. If, for example the register has the value 0x03FF which as an unsigned int is 1023, then the UI16TOF32 instruction will indeed turn this into 0x447FC000 which is 1023.0 in float. You may be good working with this value, or you may want to scale it to be between 0-1 or if you are accessing a register with a IQ format number you may want to scale it.
David Harding said:Would it be possible to get an example of a C-Callable assembly function that did conversion from UI16->F32 and back again?
If you are writing in C and do a cast, then the compiler will use the instruction - i.e.
Uint16 foo;
float32 k;
...
k = (float32) foo; // generates the UI16TOF32 instruction
Regards,
-Lori