Not able to perform Multiplication and Division operation of float variable variables

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Not able to perform Multiplication and Division operation of float variable variables

807 Views
rajkumarwadhwan
Contributor II

I am working with MagniV MTRCKTSBNZVM128 BLDC sensorless kit, (MCU part no S912ZVML12 MKH). 

I want to perform Multiplication and Division operation on floating type variables, but getting below error.

 

 

167108_167108.PNGerror.PNG

 

Below library functions give output in range -1 to 1 which is not of use.

 

Trying with MLIB_Div_FLT library but getting error, function prototype not present. 

 

167109_167109.pngpastedImage_3.png

 

 

 

167111_167111.pngpastedImage_7.png

 

I want to know any method for performing MUL and DIV operation on Float type variables. 

Any other library which gives full range result?

Labels (1)
2 Replies

580 Views
RadekS
NXP Employee
NXP Employee

Hi Rajkumar,
The standard MTRCKTSBNZVM128 code works with fractional numbers.
The S12Z do not have hardware support for floating point calculations and software emulation presents too big overhead – the multiplication and division operation of float variables will take hundreds/thousands of bus cycles.
Therefore the MLIB_Div_FLT() function is not implemented for MCUs without floating point hardware.

Of course, you may still multiply/divide floating variables by software emulation. In that case, you may simply use appropriate ANSI library (e.g. ansif.lib) and use standard “*” or “/” operands.
However, I am afraid that this will not work for motor control processing due to too big computing load.

IEEE-754 Floating Point Library.png

Note:
1. Float is IEEE32, Double is IEEE32 optimized, Long Long is 32-bit
ANSI library: ansif.lib
Compiler options:

2. Float is IEEE32, Double is IEEE32 compliant, Long Long is 32-bit
ANSI library: ansifc.lib
Compiler options: -fp_compliant

3. Float is IEEE32, Double is IEEE64 optimized, Long Long is 64-bit
ANSI library: ansidm.lib
Compiler options: -double_size=8 -bit64_code_gen mem

4. Float is IEEE32, Double is IEEE64 compliant, Long Long is 64-bit
ANSI library: ansidmc.lib
Compiler options: -fp_compliant -double_size=8 -bit64_code_gen mem

I hope it helps you.

 

Have a great day,
Radek

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

580 Views
kef2
Senior Contributor V

Radek,

  • and software emulation presents too big overhead – the multiplication and division operation of float variables will take hundreds/thousands of bus cycles.

a little correction, optimized and fully IEEE754 compliant S12Z routines take about 100-100-300 bus cycles respectively for add-mul-div. Definitely not thousands and not at all hundreds. Non -Z S12 and HC12 are bit slower with one major difference, lack of barrel shifter sometimes makes addition slower than division. Without barrel shifter and instruction to calculate first bit set position normalization could take a lot when addends differ by orders of magnitude.

Edward

0 Kudos
Reply