Skip to main content
Wil1
Associate
October 30, 2019
Question

how can i calculate log (x) or exp(x)

  • October 30, 2019
  • 5 replies
  • 5932 views

..

This topic has been closed for replies.

5 replies

Tesla DeLorean
Guru
October 30, 2019
Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Wil1
Wil1Author
Associate
October 30, 2019

how can you do it on smt32CubeIde? i tried it, that functions works with numbers ex: log(8) or log10f(1000) but when you have variable x= 100 and you do log(x) or logf(x) the compiler give an error

waclawek.jan
Super User
October 30, 2019

> when you have variable x= 100 and you do log(x) or logf(x) the compiler give an error

Which compiler? What error? Show us a minimal example exhibiting the problem - a screenshot, perhaps.

JW

PS. And please change your user name to a normal nick.

Piranha
Principal III
October 30, 2019

This is not a STM32 specific question, but a C language basics.

http://www.cplusplus.com/reference/cmath/log/

Ozone
Principal
October 30, 2019

Sorry, but the phrase " ...do it on smt32CubeIde?" suggests there is something more basic missing.

Piranha
Principal III
October 30, 2019

Yes, it's library linking and it is C basics...

Newlib-nano library doesn't include some not so often used code by default.

https://stackoverflow.com/questions/5419366/why-do-i-have-to-explicitly-link-with-libm

Wil1
Wil1Author
Associate
October 30, 2019

0690X00000ArQmHQAV.png

Piranha
Principal III
October 30, 2019

And what exactly is not clear from that error message? Check if your linker script (*.ld file) has the correct FLASH size corresponding to the real MCU part. If it has, then... reduce the code size or/and change the MCU to one with a bigger flash. This is a clear example of the fact that HAL library and CubeMX generated code is not only full of bugs, but also a bloatware...

P.C. Useful tool to analyze code and data sizes: http://www.sikorskiy.net/prj/amap/

S.Ma
Principal
October 30, 2019

If the compiler doesn't provide math.lib or if the code size is important, use interpolation, create a look up table of precalculated points and linearly interpolate between them. It's usually what is done in 8 bit MCU when speed and codesize is optimized in exchange or a lower accuracy. Sometime the variables are integer (value_x1000) to go a notch further. Check on Q31 pseudo fixed point type.

RMcCa
Senior II
October 30, 2019

Use linear interpolation. The stepsize will determine how closely the linear interpolation is to the real thing. I use Octave (mathlab) to generate comma seperated lists that i cut & paste into a C array​.