Hi
About the problem:
I took a lot of time, but I'm still stuck in doing floating point mathematical operations in my MC9S12ZVM MCU program. Maybe the question is elementary, but usually in my other projects, the compiler handles the casting between floats and integers back and forth. In the project I use, which is a demo project of one of your developments board S12ZVMLMINIBRD_BLDC_SW_CW11 the default floating point is turned off that is why once I include any explicit floating point operation I ends up with compilation error like:
Symbol __fdiv in file MC9S12ZVML128_BLDC_Sensorless_c.obj is undefined S12ZVMLMINIBRD_BLDC_SW_CW11 C/C++ Problem
I read parts of AMMCLIB manual and I tried to use the APIs like MLIB_Mul and MLIB_Div and so one, but I ended up with variables coded in 32/16 bit fixed point and did not find how to convert them back to integer.
The question:
One of the thing I want to do is:
1- Read one of the ADCs.
2- Convert to volt by multiplying the nummeric/digital value by 2.5V/1023.
3- Then scale the result using a voltage divider scale 0.85 (in my design).
4- Send the result back using CAN. Here I need to convert back from tFrac32 or tFrac16 to integer (how?)
Also is it possible and safe to enable the usual and direct floating point calculation for the demo project S12ZVMLMINIBRD_BLDC_SW_CW11 ? How (I did not find where from project settings)?
Thanks
已解决! 转到解答。
Hello,
I understand that many people coming from high-end platforms or computer programming are used to use floating point operations. But when moving to low-cost solutions, they struggle to understand benefits of fixed point arithmetic.
Here are some points to consider:
In conclusion, I would recommend to have all the data in S12ZVM in fixed-point format (represented by tFrac16 or tFrac32). It seems that your CAN protocol accepts integers. Here you can see the benefit - no need to convert anything. You can just take tFrac16 number and treat it as Word16 (or short). Fixed-point tFrac16 numbers are internally stored as integers Word16 (short). The scale is the same as above, 0 to 32767 represents 0 - 5V in real-world scale.
Solution to your task:
If you have any further questions, please don't hesitate to reply.
Best regards,
Matej
Hello,
I understand that many people coming from high-end platforms or computer programming are used to use floating point operations. But when moving to low-cost solutions, they struggle to understand benefits of fixed point arithmetic.
Here are some points to consider:
In conclusion, I would recommend to have all the data in S12ZVM in fixed-point format (represented by tFrac16 or tFrac32). It seems that your CAN protocol accepts integers. Here you can see the benefit - no need to convert anything. You can just take tFrac16 number and treat it as Word16 (or short). Fixed-point tFrac16 numbers are internally stored as integers Word16 (short). The scale is the same as above, 0 to 32767 represents 0 - 5V in real-world scale.
Solution to your task:
If you have any further questions, please don't hesitate to reply.
Best regards,
Matej