Hi all,
I want to use sine, cosine function in my application. I have created a new project and included ansitfs.lib. When I called the sin function, it halted in modf() inside function sincos().
What should I do to call the trigonometric functions?
CPKwok
Hi,
trigonometric functions, as others had already told you, are very resource hungry.
One way to solve this, if you don't need speed and/or much precision, is to use the CORDIC algorythm. It's very simply and give very good results.
And don't use floats if you really don't need them (integer math rules!! )
Hope this helps
Bye Jack
Hello
Are you debugging on real hardware or on simulator?
Can you provide a code snippet or the project showing the issue?
CrasyCat
Hi,
I debug on real hardware, the demo board DEMO9SQG8.
I created my project using the "New Project" Wizard of CodeWarrior IDE (version 5.7.0).
+ Device and connection : MC9S08QG8 , P&E multilink/ Cyclone Pro
+ Processor Expert : Device Initialization
+ C/C++ option: None, tiny, None
I changed the linked library from ansitis.lib to ansitfs.lib and added 3 lines of code.
This is the code of main.c
========================================================
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "math.h" // (1)
void MCU_init(void); /* Device initialization function declaration */
void main(void) {
double x=0; // (2)
MCU_init(); /* call Device Initialization */
x = sin(30); // (3)
for(; {
} /* loop forever */
}
========================================================
CPKwok
Yes, the problem should be ram lackage.
Does anyone know how much ram is required to call these functions
CPKwok
Hello,
It is possible to ascertain stack usage for a function using full chip simulation. Set up a test project using a much larger device to give sufficient RAM capacity, and then set the remaining unused stack to a known (non-zero) value, just prior to stepping over the trigononmetric function. Then examine the stack contents to determine the lowest address that still contains the known value. Subtract this from the current stack pointer, and you will have the stack usage for the function.
For initialising the stack contents, the following function might be of use. The first four positions below the current stack pointer are not initialised. The parameter lolimit represents the address of the bottom of the stack.
void clr_stack( word lolimit, byte val)
{
__asm {
tsx
lda val
LOOP: aix #-1
sta ,x
cphx (lolimit)
bhs LOOP
}
}
Regards,
Mac