hi,x is my frequency and it increments by 1.x changes betwwen 1 and 65535.i want to divide 1,x to get the period and show the period on lcd.i cant use long var.
what should i do?
thx
hi,x is my frequency and it increments by 1.x changes betwwen 1 and 65535.i want to divide 1,x to get the period and show the period on lcd.i cant use long var.
what should i do?
thx
Last edited by daydream; - 11th May 2012 at 06:28.
Simple answer:
Because PBP uses integer math, you won't get any meaningful value from 1/x.
You will need to think in terms of integers and scale your values appropriately.
The other alternatives is to try the floating point routines found here: http://melabs.com/resources/fp.htm
First of all, use longs because you will need the bit space. Next decide your units that will result in an integer to display. For this example, lets choose ms. Since there are 1000 ms in a second, to get period as whole ms, instead of dividing 1 by x (Hz), divide 1000 by x(Hz) which is the same as (1/x)*1000.
Obviously, if you want units of us then it's 1,000,000/x. You can see why longs are required.
Bookmarks