Can I use exponential (exp) math function in PIC16F877A code? For example like this:
double a,ans;
a=5.7;
ans=exp(0.5);
Answer
The PIC16F877A is an 8-bit microcontroller without a floating point unit (FPU). Therefore, any floating point math must be done by software emulation. Typically, this is handled through a compiler library, so it is highly dependent on which compiler you are using, which you did not specify. See if your compiler has a header file such as math.h, etc. Your compiler documentation will specify what file(s) need to be included, which functions are available, how much program/data memory and processor cycles each function will require.
Also, note that because your microcontroller can only operate on 8-bit data words, operations with ANSI C compliant "doubles", which are at least 64-bits will be extremely slow. Typically for embedded operations it is best to use type "float" if 32-bits is enough precision for your application. It will still be slow, but less extremely slow (some compiler do not even support double, and will automatically assume use of type float).
No comments:
Post a Comment