Skip to main content
LACTIC
Associate III
March 9, 2019
Question

Is stm32 micro-controls are capable to calculate Natural Logarithm ?

  • March 9, 2019
  • 2 replies
  • 2513 views

I am using Thermistor (NTC Type ) as temperature sensor .

So to calculate the temperature from adc value of STM32 I am using this formula(taken from this site :- https://www.jameco.com/jameco/workshop/techtip/temperature-measurement-ntc-thermistors.html)

1/T = 1/T0 + 1/B * ln( ( adcMax / adcVal ) – 1 )

where :-

T0= 298.15 K

B=3345.80 K

I am using Board 6-Bit adc .

So I want ask that can I use above formula in my program, because I am confuse that controller can calculate "ln (Natural Logarithm) ".

    This topic has been closed for replies.

    2 replies

    saiteja
    Associate III
    March 9, 2019

    Interface temperature sensor with any of the adc pin in controller, from pin read the value

    sysTemperature = HAL_ADC_GetValue(&hadc1); 

    sysTemp_inmV = ((float)sysTemperature/4096.0) * 3300; //ref = 3.3

    sysTemp_inCel = sysTemp_inmV/10

    LACTIC
    LACTICAuthor
    Associate III
    March 9, 2019

    Thanks.

    Here 12bit adc enable ?

    Because 4096 is value 2^12.

    waclawek.jan
    Super User
    March 9, 2019

    Following functions calculate the natural logarithm (base e):

    #include <math.h>

    double log(double x);

    float logf(float x);

    long double logl(long double x);

    You may also try to avoid the log calculation by tabulating the function at a suitable step and linearly interpolate between the steps; or by fittingthe function by polynomial.

    JW

    LACTIC
    LACTICAuthor
    Associate III
    March 11, 2019

    OK

    Amel NASRI
    ST Technical Moderator
    March 11, 2019

    Does this mean that you got the answer you look for? If yes, please click on "Select as Best" for the good answer.

    To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.