SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By kaye7877
#108480
I'm having trouble getting some math functions to work in CCS. I can get the basic sin cos, etc. to work but not having any luck with pow(). Can someone shed some light on this?

How do I get the IDE to recognize the functions when I type them in? Is there a setting for that?
By bcgrown
#108536
kaye7877 wrote:I'm having trouble getting some math functions to work in CCS. I can get the basic sin cos, etc. to work but not having any luck with pow(). Can someone shed some light on this?

How do I get the IDE to recognize the functions when I type them in? Is there a setting for that?
If you post your code and/or the compiler error it would be much easier to help you.

Have you added an #include statement for the relevant libraries?
By kaye7877
#108853
I gave up and changed the code so I don't have the original. I'm sure it is something I am not doing correctly.

I did include
math.h
float.h
The variables were also double as described in the header file.

Why, when I include them, do the functions not highlight in my CCS editor either?

I'll make some basic code and try it again and post the code.
By kaye7877
#108856
The sin function works just fine. When I add the pow function in, the compiler gives me the following errors
errors encountered during linking; "Project010MathFunctions.out" not built
placement fails for object ".text",
placement fails for object ".text", size 0xa2e (page 0). Available ranges: FLASH size: 0x7e0 unused: 0x7b6 max hole: 0x7b6

// Written on CCS 4.x
//*****************************************************************************

#include "msp430g2211.h"
#include "float.h"
#include "math.h"

volatile float fTest = 0;
volatile double dTest = (45 * 3.1415926 / 180);
volatile double dResult1;
volatile double dResult2;
volatile double a = 2;
volatile double b = 2;
const unsigned int ctest = 100;

void main(void)
{

WDTCTL = WDTPW + WDTHOLD; // Hold watchdog timer.

// Port setups.
// Port 1 P1.3 is already wired to a SMD switch SW2.
P1DIR = 0xFF - BIT3; // Pins to be outputs
P1IE = BIT3;
P1OUT = 0;


// GIE must be enabled to allow any ISR to work. Can also be set by
// the command _enable_interrupts(void) and intrinsics.h must be included
_BIS_SR(GIE); // interrupt

for(;;)
{
}
}

// Interrupt service routine for Port 1
#pragma vector = PORT1_VECTOR
__interrupt void Port_1(void)
{

_BIC_SR(GIE); // Dis-allow interrupts
P1IFG = 0;
dResult1 = sin(dTest);
dResult2 = pow(a,b);


_BIS_SR(GIE); // interrupt
}
By UhClem
#108861
kaye7877 wrote:The sin function works just fine. When I add the pow function in, the compiler gives me the following errors
errors encountered during linking; "Project010MathFunctions.out" not built
placement fails for object ".text",
placement fails for object ".text", size 0xa2e (page 0). Available ranges: FLASH size: 0x7e0 unused: 0x7b6 max hole: 0x7b6
The linker is telling you that you are trying to fit a square peg into a round hole. (code too big for memory)

Either redesign your code to control its size (avoiding library calls is good) or move to a part with more memory.