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.

floating point conversion (?) problem in L138/C6748 environment

Other Parts Discussed in Thread: TMS320C6748

Hi,

I'm trying to do realtime autio processing environment using L138/TMS320C6748.

This is sample base processing and I need floating point calculation, that's why

I just test for int32_t to float and float to int32_t, but it doesn't work well.

int32_t dat;

double dTmp;

float fDat;

while (!CHKBIT(MCASP->SRCTL12, RRDY)) {}                                     

           dat = MCASP->XBUF12;    

           dTmp = (double) dat;

           dTmp = dTmp / 32767.0;         //  if this line comment out , realtime audio work very well, but use this line no sound.

                                                           // if just use  "232.0/ 32767.0" number, not variable, works fine.

           // basically I will put additional code for floating point variable.

while (!CHKBIT(MCASP->SRCTL11, XRDY)) {}            

            MCASP->XBUF11 = dat;       // just use int32_t dat but if "dTmp/32767.0" line there not work , even dTmp/1.0 also not work.

Code Composer Version : 4.2.0.10017

 

Thanks in advance

 

 

  • Hi Doug,

    Thanks for your post.

    Basically, floating point numbers are represented in single-precision format (mapped with one 32-bit register) & double precision format (mapped with pair of 32-bit registers) as per CPU instruction set reference guide, so, the alignment between single precision & double precision floating point variable matters.

    It is recommended to use floating point variables with same precision format (single/double), i mean either use float or double to declare a floating point number, the format should be aligned everywhere in the code. In your case in the above code,

    dTmp = dTmp / 32767.0;

    Here, dTmp is declared as doube (64-bit precision) and the number 32767.0, by default, it takes as single precision floating point format (32-bit) and the operands in the numerator and denominator are mis-aligned and there comes the problem. So, I suggest you to declare a floating point variable as double and assign the number 32767.0 to the declared floating point variable and use the same in the code.

    Recommeded to use:

    double dtemp = 32767.0;

    dTmp = dTmp/ dtemp; ( Here dTmp and dtemp are declared as double, thereby, there wouldn't be any alignment issue)

    For more information, Please refer CPU Instruction set reference guide in the below link: (Refer Section 3.3.1 in page no. 71)

    http://www.ti.com/lit/ug/sprufe8b/sprufe8b.pdf

    Thanks & regards,

    Sivaraj K

    ---------------------------------------------------------------------------------
    Please click the
    Verify Answer button on this post if it answers your question.
    ---------------------------------------------------------------------------------

     

     

     

     

     

     

     

  • Thank you for your kind answer.

    I just update Code composer, It looks ok, and I've changed my code your recommedation.

    But I have another problem,

    double  dTmp,sum;

    const double  dTmp2 = (1<<24);

     

           dTmp = dTmp / dTmp2;

      sum = sum + (double) fcoef01[1] * (double) memL[0];        

      sum = sum + (double) fcoef01[2] * (double) memL[1]; 

      sum = sum + (double) fcoef01[3] * (double) memL[2];   // it has problem, if this line comment out run ok.

     

    I was worry about dynamic range problem, that's why i've cast double precision.

    I did similar program in MS visual studio, it works ok.  at that time, float also ok, but this is double

    precision.  

    Thanks in advance.

     

     

     

     

     

     

     

  • Hi Kim,

    Thanks for your response.

    If you have any new concerns, please raise it as a query in a new post, sothat, it would be easy for us to provide technical solution as compliant to process.

    I regret for any inconvenience caused.

    Thanks & regards,

    Sivaraj K