How to use sin and cos functions in TC397?

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

cross mob
Komon
Level 2
Level 2
5 questions asked 5 replies posted 10 sign-ins

I try to calculate some values ​​of sin/cos on cpu1_main, but the return value of the function is not within my expectation.

#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Ifx_Lwip.h"
#include <math.h>
#include <stdlib.h>
#include "Src/utils.h"
extern IfxCpu_syncEvent g_cpuSyncEvent;
extern float cos_test = 0;
extern float sin_test = 0;
void core1_main(void)
{

cos_test = cos(0);
printf("cos_test:%f",cos_test);
IfxCpu_enableInterrupts();
/* !!WATCHDOG2 IS DISABLED HERE!!
* Enable the watchdog and service it periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());

/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
while(1)
{
}
}

However, cos_test printf to be 2.000000, and 10000 in Debug view.

Komon_0-1679563028125.png

 

Should I link extra libraries such as libm? 

0 Likes
1 Solution
Komon
Level 2
Level 2
5 questions asked 5 replies posted 10 sign-ins

I has changed Floating-Point from "2-Fast double" to "3-Fast single" fix this problem. But I still has a question? Is TC397 not supported "double precession"? 

View solution in original post

0 Likes
7 Replies
DownyK
Level 5
Level 5
100 replies posted 10 solutions authored 250 sign-ins

Hi 

Can you show me your cos function?

0 Likes
Komon
Level 2
Level 2
5 questions asked 5 replies posted 10 sign-ins

Hi, I just include <math.h> and use:

float cos_test = cos(0);

Shall I need to find the implement of cos function?

0 Likes
Komon
Level 2
Level 2
5 questions asked 5 replies posted 10 sign-ins

Komon_0-1679798111919.png

The assembly code is here

0 Likes
Komon
Level 2
Level 2
5 questions asked 5 replies posted 10 sign-ins

I has changed Floating-Point from "2-Fast double" to "3-Fast single" fix this problem. But I still has a question? Is TC397 not supported "double precession"? 

0 Likes
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

no problem for cosine function which is C standard function. please see below screenshot.

dw_0-1679640219967.png

 

0 Likes
Komon
Level 2
Level 2
5 questions asked 5 replies posted 10 sign-ins

I has changed Floating-Point from "2-Fast double" to "3-Fast single" fix this problem. But I still has a question? Is TC397 not supported "double precession"? 

0 Likes
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

Only IEEE-754 single precision format is supported.

 

0 Likes