Using a ACOS function

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using a ACOS function

Jump to solution
1,514 Views
hpgorobr
Contributor I

Friends of Community,

In my current project, I need to limit a sinusoidal wave (in any point), and for this I need to use the ACOS function. I implement the next code in a S08RNA16 MCU:

/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"

/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

#include <math.h>

/* User includes (#include below this line is not maintained by Processor Expert) */

void main(void)
{
/* Write your local variable definition here */

float x, y;

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/

x = 0.0;
y = cos(x);

x = _M_PI/2;
y = cos(x);

x = _M_PI;
y = cos(x);

x = 2*_M_PI;
y = cos(x);

x = 1.0;
y = acos(x);

x = 0.9;
y = acos(x);

x = -1.0;
y = acos(x);

/* Write your code here */
/* For example: for(;;) { } */
for (;;)
{

}

/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
}

When the control of program reach the point to calculate the ACOS of 0.9, the Simulator of CodeWarrior 11.1 goes to this screen (rtshc08.c) and stop (the program does not calculate the ACOS for that value):

#pragma NO_EXIT
static void _FADD_Common(void) {
asm {
JSR _UNPACK_k_to_K;
JSR _UNPACK_j_to_L;
JSR _FADD_K_is_K_plus_L;
JSR F_NORMK;
_SRET
JSR _PACK_K_to_k; /* returns itself */
}
}

My question is: Why am I finding this problem for a valid number (0.9) for the ACOS function?

I appreciate an orientation for solve this problem.

0 Kudos
Reply
1 Solution
1,478 Views
ZhangJennie
NXP TechSupport
NXP TechSupport
0 Kudos
Reply
3 Replies
1,490 Views
hpgorobr
Contributor I

Hello Jun,

You are right, I change the Stack position using the next sentence and the program compile OK work OK:

// Setting of Stack Pointer in the end of RAM
__asm LDHX #RAM_LAST+1 ; // point one past RAM
__asm TXS ; // SP<-(H:X-1)

Thank you very much Jun for your help.
Sincerely
Horacio Gorosito

0 Kudos
Reply
1,479 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

You are welcome!

0 Kudos
Reply
1,498 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi hpgorobr

Your problem is cased by stack over flow. 

The default stack size is 0x80. for example, increase it to 0x200, regenerate code and build, this can fix the issue

ZhangJennie_0-1614329078296.png

Besides, HCS08RNA16 on chip RAM is limit, only 4kB. Wile math lib functions like you are you using are memory consuming, If your application has many trigonometric function computation, I suggest you creating a trigonometric function table rather than call math lib functions directly.

 

Best Regards

Jun Zhang

 

0 Kudos
Reply