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
i dont know how to deal with floating point values in microcontroller programming. can anyone help me the VERY same way you "deal with floating point values in ANY programming". Erik
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
"if i do thhis will it work in microcontroller programming" usually not unless you have a really smart compiler try ah = (((float)count * (float)range)/(3600.0 * 1000.0)); That should get you the result you want. Though if you using an 8 bit uC, you way want to investigate using fixed point arithmatic instead of floating point. If your doing this calculation many times, you can give your uP significant performance increase. Andy
thanks andy , its working. thanks