Hi
I used TMS320F28335 controller. Can you please tell me how can I convert an integer number (16 bit which is the input to the ADC) to float number. Then how can change the 32bit float number to 16bit integer.
Thank you very much
Jassim
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.
Hi
I used TMS320F28335 controller. Can you please tell me how can I convert an integer number (16 bit which is the input to the ADC) to float number. Then how can change the 32bit float number to 16bit integer.
Thank you very much
Jassim
I am not 100% on this as I haven't tried it, but I know on the TMS320F28335 there are assembly commands to do the conversions. This probably means that the C compiler has knowledge of these and will compile code using them (hopefully). So one way to convert may just be using a simple cast in C, i.e. floatvar = (float) intvar or intvar = (int) floatvar. If this doesn't work then you could use short assembly routines to do the conversions using the in built conversions - these may be floating around somewhere already written.
Tim
As is usually the case, it depends on what you are trying to do.
The '335 has both signed and unsigned 16 and 32 bit integer to float instructions and their inverses. See UI16TOF32, I32TOF32, F32TOI16R etc.
If you're working in C the compiler will generate the appropriate assembly instructions as long as your types are correct.
If you are trying to convert back to a 16 bit value from your 32 bit floats, you have to be careful that your processing has not resulted in an overflow of 16 bits. Also keep in mind that the precision of the 32 bit floats is 24 bits.