How to use "sqrt" function in XMC4200?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
0 Likes
6 Replies
Not applicable
HI,

What's wrong with this function? Did you add this code line in your code: #include ?

Regards.
Daryl
0 Likes
Not applicable
Yeap i am already add the #include

compiler will not giving any error if call function such a way, giving the const at the input

sqrtf(9);

however if the input is a variable, then compiler report an error

float dVal;

dVal = a*b;
sqrtf(dVal);

Regards
Joy
0 Likes
Not applicable
HI Joy,

It is working fine on my setup. I added the following code lines.

float a,b,c;

c=9.2;
b=c*1.2;
a = sqrtf(b);


What is the error reported in your DAVE IDE?

Regards,
Daryl
0 Likes
Not applicable
Daryl Neo wrote:
HI Joy,

It is working fine on my setup. I added the following code lines.

float a,b,c;

c=9.2;
b=c*1.2;
a = sqrtf(b);


What is the error reported in your DAVE IDE?

Regards,
Daryl


code...
/////////////////////////////////////////////////////////////////////////////////////////////////
//**************************************************************************
// Includes
//**************************************************************************
#include //Declarations from DAVE3 Code Generation
#include
#include
#include "GPIO.h"
#include "general.h"

void Get_Vout(float power, float dVBAT, float dResistance)
{
float Vout=0;
float duty;
unsigned char mode;

IO_Ctr_BUCK_OD(1);

mode = 0;

Vout = sqrtf(power*dResistance);
}
/////////////////////////////////////////////////////////////////////////////////////////////////

Compile result:

Invoking: ARM-GCC C Linker
"C:\DAVE-3.1.10\DAVE-3.1.10\DAVE-3.1.10\ARM-GCC/bin/arm-none-eabi-gcc" -T"../ECIG_ENG.ld" -nostartfiles -L"C:\DAVE-3.1.10\DAVE-3.1.10\DAVE-3.1.10\eclipse\/../CMSIS/Infineon/Lib" -L"C:\DAVE-3.1.10\DAVE-3.1.10\DAVE-3.1.10\eclipse\/../Examples/Lib" -L"C:\DAVE-3.1.10\DAVE-3.1.10\DAVE-3.1.10\eclipse\/../emWin/Start/GUI" -Wl,-Map,"ECIG_ENG.map" -mcpu=cortex-m4 -mthumb -o "ECIG_ENG.elf" "@makefile.rsp"
source/PWM.o: In function `Get_Vout':
PWM.c:(.text.Get_Vout+0x26): undefined reference to `sqrtf'
collect2.exe: error: ld returned 1 exit status
make: *** [ECIG_ENG.elf] Error 1

**** Build Finished ****
0 Likes
Not applicable
Hi DaryI

my code...
/////////////////////////////////
//**************************************************************************
// Includes
//**************************************************************************
#include //Declarations from DAVE3 Code Generation
#include
#include
#include "GPIO.h"
#include "general.h"

/**************************************************************************************************************/
void Get_Vout(float power, float dVBAT, float dResistance)
{
float Vout=0;
float duty;
unsigned char mode;

IO_Ctr_BUCK_OD(1);

mode = 0;

Vout = sqrtf(power*dResistance);
}
/**************************************************************************************************************/


Building target: ECIG_ENG.elf
Invoking: ARM-GCC C Linker
"C:\DAVE-3.1.10\DAVE-3.1.10\DAVE-3.1.10\ARM-GCC/bin/arm-none-eabi-gcc" -T"../ECIG_ENG.ld" -nostartfiles -L"C:\DAVE-3.1.10\DAVE-3.1.10\DAVE-3.1.10\eclipse\/../CMSIS/Infineon/Lib" -L"C:\DAVE-3.1.10\DAVE-3.1.10\DAVE-3.1.10\eclipse\/../Examples/Lib" -L"C:\DAVE-3.1.10\DAVE-3.1.10\DAVE-3.1.10\eclipse\/../emWin/Start/GUI" -Wl,-Map,"ECIG_ENG.map" -mcpu=cortex-m4 -mthumb -o "ECIG_ENG.elf" "@makefile.rsp"
source/PWM.o: In function `Get_Vout':
PWM.c:(.text.Get_Vout+0x26): undefined reference to `sqrtf'
collect2.exe: error: ld returned 1 exit status
make: *** [ECIG_ENG.elf] Error 1

**** Build Finished ****
0 Likes
Not applicable
Did you add the 'm' option to the project properties ?

1702.attach
0 Likes