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.

how to use 32*32 hardware multiplier.

Dear All,

   I am using 16* 16 multiplier in my program.In program I an first accumulating the variables & then multiplying them.I am using this for measurement purpose.

In one single cycle of AC mains(of 20milli seconds) I am taking 80 samples .ie.4096 samples/Second.So I am accumulating & squaring each samples .I am doing this for every 80 samples .But using 16*16 hardware multiplier result gets overflow.So that I want to use 32*32 multiplier.I was using 16*16 hardware multiplier in following way.

union LONG_UNION
{
//unsigned char c[4];
unsigned int i[2];
signed long l;
};
union LONG_UNION MAC_RESULT;

signed int MAC_REG_A,MAC_REG_B;


RESLO = MAC_RESULT.i[0]; //lower 16 bit result of previous multiplication should be stored in RESLO
RESHI = MAC_RESULT.i[1]; //higher 16 bit result of previous multiplication should be stored in RESHI

MACS = MAC_REG_A; //for signed multiplication and accumulate
OP2 = MAC_REG_B;

_nop();

MAC_RESULT.i[0] = RESLO;  //Here MAC Accumulator will have the result
MAC_RESULT.i[1] = RESHI;

I am using 16*16 multiplier as shown in above.So the results were perfectly accurate when ac mains cycle have smaller values.But it gets exceeded when ac mains increased.So I want to use 32*32 multiplier.

I can use it in following way.

MPY32L = // Load lower 16 bits of operand 1
MPY32H =; // Load upper 16 bits of operand 1

OP2L =  // Load lower 16 bits of operand 2
OP2H = // Load upper 16 bits of operand 1

But in C I can define maximum upto 32 bit variable only.ie.long data type or float data type.So how to define union as define in above to have 64 bit data type.& how to define that.& how to define 64 bit data types???????????

Thanking you ,

Gokul Tile

  • The latest versions of the compilers should support the 'long long' 64 bit type. Try this. Else you have to save the 64 bit result in two long variables, and then turn them into a float.

    float f = ((float)MSDW<<32)+LSDW;

    I never tried myself (MSPGCC supports long long), but it should do.

    Of course you can define a struct that contains two long ints. However, a union of long ints and a float for conversion won't work. float uses a completely different storage structure (exponent and mantisse)

  • Thanks you sir,

                  I am using CCS 5.2ver compiler & which supports long long(64 bit) data type.& After using long long data type I am getting accurate result.

    Thanks a lot.

    Gokul Tile

**Attention** This is a public forum