Monday, 18 June 2018

microcontroller - Can I use math functions in PIC16F877A code?


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

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...