How to use log function in S9S12GA240 controller

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

How to use log function in S9S12GA240 controller

474 Views
punithb
Contributor I

Hi All,

 

I need to use ln function to read NTC sensor readings. if i use log(number , 2.71828182846) which yields to ln(number). but log function giving wrong value. Could you please tell how to log function in this controller.

Labels (1)
0 Kudos
1 Reply

413 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

The CodeWarriror IDE  help says:

#include <math.h>

double log (double x);

float logf(float x);

Description

log() computes the natural logarithm of x.

Return

ln(x), if x is greater than zero. If x is smaller then zero, NAN is returned; if it is equal to zero, log() returns negative infinity. In both cases, errno is set to EDOM.

So you should be sure:

  • The function uses correct types.
  • You have included math.h. and you have used correct function logf, log.
  • You have opened project with floating point arithmetics support. (ansib.lib should be visible in the Libs directory in project window)

#include <hidef.h>

#include "derivative.h"

#include <math.h>

int   a;

volatile float y;

void main(void)

{

  

  for(;;)

   {

     for ( a=100; a<10000; a+=100)

       {

         y = logf( a );

         asm nop;

       }

   }

}

A full example project is attached.

Best regards,

Ladislav

0 Kudos