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/MSP430G2553: Working with floating point values and sqrt() function

Part Number: MSP430G2553

Tool/software: Code Composer Studio

Hello guys,I have been working with msp430 g2553 for first collecting the analog data from sun sensor and then converting it to digital form.After getting values from sun sensor from all three directions I want to find the vector of the light source with respect to my setup.For finding vector I need a sqrt() function inside with I'm doing some multiplication.When I compiled the code it is showing some sort of warning that the msp 430 is not having the multiplying hardware and also that I'm dealing with floating point values so it is becoming power intensive.I'm just a beginner and I don't know how to operate with math functions and floating point values.

Someone please help me by earliest.

I'm attaching my code here

#include <msp430g2553.h>

#include <stdio.h>

#include <math.h>

void main(void) {

unsigned int flag;
unsigned int sensor[3];
long int sunvec[3];
long int vecx;
long int vecy;
long int vecz;


WDTCTL = WDTPW + WDTHOLD;
//TACCTL0 &= ~CCIE;
//P3SEL = 0x00;
//P3REN = 0X06
//P3OUT = 0x02;
//P3DIR |= 0x02;
//P3DIR |= 0x01;


flag = 0;
for(;;)
{
if ( flag == 0 )
{
sensor[0] = 0;

ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON;

ADC10CTL1 = INCH_0 + ADC10DIV_3;

ADC10AE0 |= BIT0;

ADC10CTL0 |= ENC + ADC10SC;

// __bis_SR_register(CPUOFF + GIE);

sensor[0] = ADC10MEM;

ADC10CTL0 &= ~ENC;

flag = 1;

}

if (flag == 1)

{

sensor[1] = 0;

ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON ;

ADC10CTL1 = INCH_1 + ADC10DIV_3;

ADC10AE0 |= BIT1;

ADC10CTL0 |= ENC + ADC10SC;

// __bis_SR_register(CPUOFF + GIE);

sensor[1] = ADC10MEM;

ADC10CTL0 &= ~ENC;

flag = 2;

}

if ( flag == 2 )

{

sensor[2] = 0;

ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON ;

ADC10CTL1 = INCH_2 + ADC10DIV_3;

ADC10AE0 |= BIT2;

ADC10CTL0 |= ENC + ADC10SC;

// __bis_SR_register(CPUOFF + GIE);

sensor[2] = ADC10MEM;

ADC10CTL0 &= ~ENC;

flag = 0;

}


long int mul= sensor[0]*sensor[0] + sensor[1]*sensor[1] + sensor[2]*sensor[2];

long int deno=sqrt(mul);

vecx = sensor[0]/deno;

vecy = sensor[1]/deno;

vecz = sensor[2]/deno;

sunvec[0]=vecx;
sunvec[1]=vecy;
sunvec[2]=vecz;

}
}

With Regards

Tejas

  • The ULP notice is correct, in that your program will be bigger, and run slower (ergo more power) with floating point than without. On the other hand, if you need it, you need it, and ignoring (or even disabling) the ULP notice won't stop you.

    If you later discover that your program doesn't meet your constraints -- it doesn't fit into the G2553 flash or doesn't meet your deadlines -- you can try Googling for an integer square root function or employ TI's IQMathLib.
  • thanks bruce,
    Also there was some warning that was telling me to move the code to RAM during run time .What does that actually means?
  • What it means is that code run from RAM is much faster than code in flash. You can tell the linker to automagically move certain functions to RAM to take advantage of this. If the performance is fine or you are tight on RAM, don't bother.
  • Thanks Keith,

    This is true but now what I should do I'm not able to make out . Please tell me how to find sqrt with floating point.Even I realized the problems that is happening but the issue is I am not able to make out a solution for this and everyone is giving different solutions.Can someone please look through the code of sqrt() because when I'm commenting the sqrt() ,the code is running fine but when I involve the square-root it is showing the warning.So what are the alternatives for this.I even tried sqrt(4) but it is still showing the same error

  • ULP Advice is just that -- Advice. It is not a Warning. Warnings/Errors from the compiler point to probable malfunctions; ULP Advice is merely a suggestion.

    I think Keith and I agree: Ignore it. If there's an actual malfunction, it will show up elsewhere.

    You can disable these messages using Project->Show Build Settings->ULP Advisor.
  • Many people that use the MSP series are fighting over uAs. TI helpfully adds the ULP advice messages so that those folks can reduce power consumption to the absolute minimum. In your case, if current is not an issue, you can safely ignore the advice and use sqrt() just like you would with any embedded processor.
  • Thanks Keith,I hope It works like that.Thanks a lot

**Attention** This is a public forum