cancel
Showing results for 
Search instead for 
Did you mean: 

Floating point

andrea2399
Associate II
Posted on June 09, 2014 at 12:53

Hi, I can't stand why my stm32f4 does not do the floating point calculation.

Frequency = (RCC_Clocks.HCLK_Frequency)/2 / (IC2Value * (TIM4->PSC+1));

Frequency is a float variable, but when i read it with ''printf'' there's an integer inside.
4 REPLIES 4
chen
Associate II
Posted on June 09, 2014 at 13:04

Hi

Basic (stupid) question :

Are you telling printf to print a float number?

printf( tmpString, ''%f'', floatVar )

ivani
Associate II
Posted on June 09, 2014 at 14:07

I could guess all variables in the expression are integers, so the calculation is done in int and then assigned (cast) to float.

It is necessary to cast the intermediate result to float before the first division.

andrea2399
Associate II
Posted on June 09, 2014 at 15:39

The printf is right. The problem was the IC2Value, now i've declared it ''float''. Thank you!

psandesh007
Associate II
Posted on June 10, 2014 at 11:31

Hi,

Try this method for your old code,i.e declare IC2Value as you declared before. I think it will work

Frequency =(float)((RCC_Clocks.HCLK_Frequency)/2 / (IC2Value * (TIM4->PSC+1)));