Floating Point Unit(FPU) is a construct for running floating-point arithmetic. It is generally realized by circuit and applied in computer chip. It is a big development after the integer arithmetic unit, because before the invention of the floating-point arithmetic unit, the floating-point arithmetic in the computer is simulated by integer arithmetic, and the efficiency is very poor. Floating-point arithmetic machines are bound to have errors, but scientific and engineering calculations still rely heavily on floating-point arithmetic machines -- it's just that accuracy must be considered in program design.
Geehy MCU APM32E103 adds an FPU unit based on the compatible Sxx32F103. It can greatly improve the efficiency of floating-point arithmetic.
The use of the APM32E103 FPU is also simple, as long as the FPU is used as a peripheral, for example, to configure the FPU clock. The official SDK provides FPU library, and FPU function library.
The FPU library declares the floating-point arithmetic functions that can be used in sc_math.h:
To do floating-point arithmetic in C, you can call math.h to do floating-point arithmetic.
Let's simply compare the APM32E103 FPU with the same sin() and cos operations in math.h and see how much time it takes.
The idea is to reset the TMR5 count and read the count before and after 100 floating-point operations to calculate the time taken.
Using the serial port, you can print out the floating-point operation value and the time used.
Results when the input Angle is 10°.
For an input Angle of 120° :
From the calculation results to compare, floating-point arithmetic values are still more accurate.
The FPU of APM32E103 improves the computing efficiency obviously. At present, because the calculation is completed by hardware, different input values have no effect on the operation time.
sin() and cos() with math.h require transformations that take different times for different input values.
On the whole, the FPU of APM32E103 supports the floating-point operation function, the efficiency and accuracy of the operation are very good, and it is more suitable for the occasion of multiple floating-point operations.
Comments
Please log in or sign up to comment.