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.

Integer to float

Other Parts Discussed in Thread: TMS320F28335

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

 

  • Well, I am sure there are various ways but one good way is to use IQ math functions to coverter ADC values to any Q number or to float number. Check out the IQmath manual for additional information/references.

  •  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.

     

  • Thank you Very much

    I work on C language