Skip to main content
andrea2399
Associate
June 9, 2014
Question

Floating point

  • June 9, 2014
  • 4 replies
  • 970 views
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.
    This topic has been closed for replies.

    4 replies

    chen
    Associate II
    June 9, 2014
    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
    Visitor II
    June 9, 2014
    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
    June 9, 2014
    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
    June 10, 2014
    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)));