Skip to main content
LACTIC
Associate III
Mar 9, 2019 5:38 AM UTC
Question

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

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.

    5 replies

    saiteja
    Associate III
    Mar 9, 2019 7:21 AM UTC

    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
    Mar 9, 2019 8:05 AM UTC

    Thanks.

    Here 12bit adc enable ?

    Because 4096 is value 2^12.

    waclawek.jan
    Super User
    Mar 9, 2019 11:25 AM UTC

    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
    Mar 11, 2019 4:17 AM UTC

    OK

    Amel NASRI
    ST Technical Moderator
    Mar 11, 2019 7:34 AM UTC

    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.