This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

floating point calculations

hi all, i want to calculate the result of the expression

ah = (range * count*10*resolution)/(3600*1000);

and later add it to the previous value of it
ahfinal = ahfinal + ah;


in brief to explain what i want actually is: count is the count of pulses on timer/counter , now these pulses are caliberated as

range ------> 1000 pulses
xxxx -------> count pulses

now these are to be cailberated into one hour

so ah = xxxx/3600;
now i need a resolution of (1 or 2 or 3 decimals depending on the variable resolution. next the final result should be integrated( i mean added to its previous value ahfinal = ahfinal+ah)


here
range (25, 75,100)
resolution(1, 2, 3)
count(some bog number assume around 1000).

i dont know how to deal with floating point values in microcontroller programming. can anyone help me

thanks in advance
narender

Parents
  • hi erik

    in simple c , i wil just declare a variable as float

    eg:

    #include<AT898252.h>

    void main()
    {
    float ah, ahfinal;
    unsigned int count = 1000;
    unsigned int range = 25;
    ah = ((count * range)/(3600 * 1000));
    ahfinal = ahfinal + ah;

    }

    if i do thhis will it work in microcontroller programming.

    when i run and debug , the value in ah and ahfinal is always zero

Reply
  • hi erik

    in simple c , i wil just declare a variable as float

    eg:

    #include<AT898252.h>

    void main()
    {
    float ah, ahfinal;
    unsigned int count = 1000;
    unsigned int range = 25;
    ah = ((count * range)/(3600 * 1000));
    ahfinal = ahfinal + ah;

    }

    if i do thhis will it work in microcontroller programming.

    when i run and debug , the value in ah and ahfinal is always zero

Children