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.

CCS: MSP430 + LEA - Issue with DSPLib



Tool/software: Code Composer Studio

Customer has a problem with msp_mpy_q15 command of DSPLib_1_20_03_01.

They used several LEA functions (FFT, IFFT, MAX etc) but face problems with the multiplication commend (msp_mpy_q15). They are not receiving correct results (vector filled with 0 and sometimes +-1).

Could you please comment where the error is?

Code (add command is working)

#include "dsplib/include/DSPLib.h"

 

#define VECTOR_LENGTH   8

// Load data into shared Ram to work with LEA

DSPLIB_DATA(src1,4)

DSPLIB_DATA(src2,4)

DSPLIB_DATA(dst,4)

_q15 src1[VECTOR_LENGTH]={1,2,3,4,5,6,7,8};

_q15 src2[VECTOR_LENGTH]={1,5,3,4,5,6,7,8};

_q15 dst[VECTOR_LENGTH];

 

int main(void) {

 

    msp_status status; // Status of command

    //--------------------------------------------------------------------------------------------------------------

    msp_mpy_q15_params mpyParams; // data struct

    mpyParams.length = 8; //length of Vector

    // Run LEA mpy calculation

    status = msp_mpy_q15(&mpyParams, src1, src2, dst);

    //--------------------------------------------------------------------------------------------------------------

 

 

    //--------------------------------------------------------------------------------------------------------------

    msp_add_q15_params addParams; // data struct

    addParams.length = 8; //length of Vector

    // Run LEA add calculation

    status = msp_add_q15(&addParams, src1, src2, dst);

    //--------------------------------------------------------------------------------------------------------------

}

 

  • Hi Marco,

    The function is actually operating correctly but your customer is using as if it were an integer multiply routine. However, the _q15 inputs are integer representations of floating point numbers. You can find more information on this data type in the Fixed-Point Data Type section of the DSPLib User's Guide.

    In this particular case the integer values 1,2, 3, 4, etc are representations of 0.00003051758, 0.00006103515625, etc using the equation f_q15(x) = x *2^-15. So when src1[1] *src2[1] is executed the real result is 0.00006103515625 * 0.000152587890625 = 0.0000000093132257. Then when this number is converted back to an integer representation by dividing by 2^-15 the result is 0.00030517578 and the integer value of this number is 0. 

    A better test of the function would be the following:

    #include "driverlib.h"
    #include "dsplib/include/DSPLib.h"
    
    #define VECTOR_LENGTH   8
    // Load data into shared Ram to work with LEA
    // _Q15(x) macro converts floating point representation to integer representation
    DSPLIB_DATA(src1,4)
    _q15 src1[VECTOR_LENGTH]={_Q15(0.1),_Q15(0.2),_Q15(0.3),_Q15(0.4),_Q15(0.5),_Q15(0.6),_Q15(0.7),_Q15(0.8)};
    
    DSPLIB_DATA(src2,4)
    _q15 src2[VECTOR_LENGTH]={_Q15(0.1),_Q15(0.2),_Q15(0.3),_Q15(0.4),_Q15(0.5),_Q15(0.6),_Q15(0.7),_Q15(0.8)};
    
    DSPLIB_DATA(dst,4)
    _q15 dst[VECTOR_LENGTH];
    
    _q15 expecResult[VECTOR_LENGTH] = {_Q15(0.01),_Q15(0.04),_Q15(0.09),_Q15(0.16),_Q15(0.25),_Q15(0.36),_Q15(0.49),_Q15(0.64)};
    
    int main(void) {
    
        WDTCTL = WDTPW | WDTHOLD;       // Stop watchdog timer
    
        msp_status status; // Status of command
    
        P1OUT &= ~BIT0;
        P1DIR |= BIT0;
    
        //--------------------------------------------------------------------------------------------------------------
        msp_mpy_q15_params mpyParams; // data struct
        mpyParams.length = 8; //length of Vector
        // Run LEA mpy calculation
        status = msp_mpy_q15(&mpyParams, src1, src2, dst);
        __no_operation();
        if(status != MSP_SUCCESS)
        {
            P1OUT |= BIT0; //Signal there was a  calculation error
        }
        //--------------------------------------------------------------------------------------------------------------
    
        uint8_t i = 0;
        while(i < VECTOR_LENGTH)
        {
            if(dst[i] != expecResult[i])
            {
                P1OUT |= BIT0; //Signal there was a  calculation error
            }
            i++;
        }
    
        //--------------------------------------------------------------------------------------------------------------
        msp_add_q15_params addParams; // data struct
        addParams.length = 8; //length of Vector
        // Run LEA add calculation
        status = msp_add_q15(&addParams, src1, src2, dst);
        __no_operation();
        if(status != MSP_SUCCESS)
        {
            P1OUT |= BIT0; //Signal there was a  calculation error
        }
        //--------------------------------------------------------------------------------------------------------------
    }
    

    Let me know if you have any questions. 

    Best regards, 
    Caleb Overbay

**Attention** This is a public forum