2015-04-29 11:07 PM
Hello,
I use STM32F407 discovery board and keil uvision4. I want to do matrix communication but I meet the following weird problems. My code is as below.float Num[2]= {0.000144962712488309, -0.000602215526678967};
float Den[2]= {1, -5.62630205892449};float ACCd[2];
printf(''ACC 3 \n''); for (int i=0; i<2; i++) { ACCd[i]=Num[i]*Den[i]; } printf(''ACC 4 \n''); It can compile but I can't see any result even the print ofACC 3
. When I modified the code tofloat Num[2]= {0.000144962712488309, -0.000602215526678967};
float Den[2]= {1, -5.62630205892449};
float ACCd[2];
printf(''ACC 3 \n''); ACCd[0]=Num[0]*Den[0]; ACCd[1]=Num[1]*Den[1]; printf(''ACC 4 \n''); And it can work fine. Do I miss some constraints about the ST?Thanks #stm32 #matrix2015-04-30 03:15 AM
I don't see a grave issue in the provided code.
Have turned off any optimisation, and did you try to single-step in a debugger ? However, there are two issues you migth stumble upon later: float Num[2]= {0.000144962712488309, -0.000602215526678967};
First, these are not floating point, but double constants. Make it 'float' with an 'f' at the end (like '0.000144
f
'), otherwise this will impact performance. Second, 'float' is not capable of holding the precision you specified. Check if/how this affects your algorithm.2015-04-30 04:37 AM
Not sure I like the C++ syntax, and the lack of real context of the code, but it looks reasonable enough.
I'd make sure I pulled in math.h, check the MicroLib, FPU and optimization options.2015-05-03 08:47 AM