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.

Multiplication function for fraction multiplication using hardware multiplier

Other Parts Discussed in Thread: CC430F5137, MSPMATHLIB

Hello,

I am using cc430f5137 with CCS4.Can I know how to change the two 16bit number multiplication function to multiply a fractional number (negative or positive for example 0.00378304197175636 or -0.0123878480564485) with 16 bit integer.

The two 16bit number multiplication function used is 

6825.5658.mul16.txt
//*****************************************************************************
// THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
// REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
// INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
// COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
// TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
// POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
// INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
// YOUR USE OF THE PROGRAM.
//
// IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
// CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
// THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
// OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
// EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
// REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
// OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
// USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
// AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
// YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
// (U.S.$500).
//
// Unless otherwise stated, the Program written and copyrighted
// by Texas Instruments is distributed as "freeware".  You may,
// only under TI's copyright in the Program, use and modify the
// Program without any charge or restriction.  You may
// distribute to third parties, provided that you transfer a
// copy of this license to the third party and the third party
// agrees to these terms by its first use of the Program. You
// must reproduce the copyright notice and any other legend of
// ownership on each copy or partial copy, of the Program.
//
// You acknowledge and agree that the Program contains
// copyrighted material, trade secrets and other TI proprietary
// information and is protected by copyright laws,
// international copyright treaties, and trade secret laws, as
// well as other intellectual property laws.  To protect TI's
// rights in the Program, you agree not to decompile, reverse
// engineer, disassemble or otherwise translate any object code
// versions of the Program to a human-readable form.  You agree
// that in no event will you alter, remove or destroy any
// copyright notice included in the Program.  TI reserves all
// rights not specifically granted under this license. Except
// as specifically provided herein, nothing in this agreement
// shall be construed as conferring by implication, estoppel,
// or otherwise, upon you, any license or other right under any
// TI patents, copyrights or trade secrets.
//
// You may not use the Program in non-TI devices.
//*****************************************************************************
//16x16=>32 multiply
//int32_t mul16(register int16_t x, register int16_t y)

// Use with IAR versions >= 4.0
	    public  mul16

	    RSEG    CODE
mul16

#define     x1      r9
#define     z0      r14
#define     z1      r15
#define     x       r12
#define     y       r13

            push    r9

	    clr	    z0
	    mov	    z0,z1
	    mov	    z0,x1
	    tst	    x
	    jge	    xbooth_2
	    mov	    #-1,x1
	    jmp	    xbooth_2

xbooth_6
	    add	    x,z1
	    addc    x1,z0
xbooth_1
	    rla	    x
	    rlc	    x1
xbooth_2
	    rra	    y
	    jc	    xbooth_5
	    jne	    xbooth_1
	    jmp	    xbooth_4

xbooth_5
	    sub	    x,z1
	    subc    x1,z0
xbooth_3
	    rla	    x
	    rlc	    x1
	    rra	    y
	    jnc	    xbooth_6
	    cmp	    #0FFFFh,y
	    jne	    xbooth_3

xbooth_4
            mov     z1,r12
            mov     z0,r13

            pop     r9

            ret
            end

#include <msp430.h>

long mul16(register int x, register int y);
long result;
int main(void)
{
    int x=1;
    int y=1;
    result=mul16(x,y);
     __bis_SR_register(LPM0_bits);             // Enter LPM4
     __no_operation();
}

Thanks.

  • You shall look for MSPMATHLIB

  • I am getting error as shown in the below image when followed as 

    downloaded http://www.ti.com/tool/MSPMATHLIB free software from here ,followed instruction here http://www.ti.com/lit/ug/slau499/slau499.pdf  added file->msp430_small_code_small_data (last option)

    I am using ccs5.5.

    can I know hwo to overcome this error.thanks.

  • Where is msp430_math.h file installed in relation to your project? Have you added that directory to your project's include search path?

    The error is pretty simple... it can't find the .h file you added to the top of your main.c file.

  • thanks for your suggestion that solved the problem by adding the msp430_math.h file as shown below

    My apologies for the mistake I made with the question itself(I corrected the question as using hardware multiplier),I was actually planning to implement the

    multiplcation fucntion for a fraction number positive or negative(example 0.0037830419 or -0.0123878480)with an 16 bit integer using the hardware multiplier .

    so I think I don't need this MSPMATHLIB.

    I found only 1 example in the TIResource_explorer.can someone provide if there are other implemented functions with the hardware multiplier or guidelines to do so.

    Thanks.

  • Search on Q15 formatted numbers in Google/etc. This is a way to represent fractional numbers -1 < x < 1 using a sign bit and 15 fractional bits.

    You can then multiply that Q15 number with another 16-bit integer number and get a result that is 32 bits, 15 of which represent the fractional portion. If you need just the integer portion after the mult, you can right shift the number back to a 16-bit integer.

    -> Read this <-

  • Hello

    I'm using CCS 5.5 as well and I added the library which is in the include path but I can't seem to find (or create) "msp430_math.h" - am I missing something?  I have the library included in my project root but I can't find a trace of "msp430_math.h" on my computer anywhere.

    Thank you

    Chris

  • Brian, multiplying two Q15 values gives a Q30 value. Since the Q15 values are always between 1 and -1 (not including them), the result is always just a fraction again and has no integer part.

    Using the MSP hardware multiplier with MPYFRAC set, will automatically do the shift and return a properly formatted Q15 result in RES1 register while RES2/RES3 return a Q31 result. This shift happens during the read and doesn’t affect the multiplication result register content itself. So one can switch between fractal and standard result format after the multiplication.

    Using combined numbers (like Q24 in a 32 bit variable, with integer part) makes the adjustments after the operation more tricky.

     Christopher,
    #include “msp430_math.h” searches the project-specific include path, while  #include <msp430_math.h> searches the system (compiler) include path. Be sure the header file is in one of them and use the right include syntax.

  • Thanks Jens - I think I'm actually missing the .h file somehow.  Is there somewhere I could download it? I have the library (.lib)

  • It should have come with the library. So how did you get the lib and how did you intall it? Manually or was there an isntall script? I didn't ever do it myself, so I don't know how the lib is provided and installed.

    Did you try a file search on yor HD? Maybe it got installed to a standard path but your installation uses a non-standard install path, so the header file ended up where the compiler usually is.

    Chances are, if the header file isn't where it should be, you'll also get problems linking the lib later.

  • I'm assuming it was installed with CCS5 though I can't find any trace of a file named "msp430_math.h" in my system anywhere.  The lib files are in my C:\ti\ccsv5\ccs_base\msp430\lib\, only file in there other than the .lib files is a "libmath.a"

  • AFAIK, the libmath.a is a so-called vector library. Depending on the used code and data model, it includes the .lib file with the proper code for the currently used memory model.

    I really don’t know where the header file went.  I still didn’t find the time to install my CCS (I’m using MSPGCC at work)

    But normally it should be somewhere below a folder named ‘include’.

  • Hello,

    Is the problem of msp430_math.h header file missing solved..?

    Please let me know. Even I am facing the same problem.

    Thanks in advance :-)

  • Hello,

    My problem also same. I could not find the msp430_math.h in my CCS5.5

    any update on this issue.

    Thanks,

    Arul.

  • Jens-Michael Gross said:
    Brian, multiplying two Q15 values gives a Q30 value. Since the Q15 values are always between 1 and -1 (not including them), the result is always just a fraction again and has no integer part.

    True. But that isn't what I suggested. I said to multiply the Q15 with an integer. Or more precisely multiplying a Q0.15 with a Q15.0. The result is a Q15.15. Sign-extended right shift of 15 bits leaves you with the integer result of and INT * FRAC math operation.

    EDIT: You can also see that this was the case the OP asked about. fractional number multiplying by an integer.

  • Have same problem. Using CCS 6.0 and can't fint the  msp430_math.h

  • Aziz Sharipov said:
    Have same problem. Using CCS 6.0 and can't fint the msp430_math.h

    MSPMATHLIB is integrated into CCS6:

    http://e2e.ti.com/support/microcontrollers/msp430/f/166/p/345026/1245731.aspx#1245731

**Attention** This is a public forum