I am calculating force from acceleration which is output as a variable PWM. More acceleration the longer the T1 is high. The documentation for the sensor says that fixed point math will be fine. Per your description, I can just multiply by 2 to essentially shift the decimal point over. and then shift it back when the calculation has concluded. Do I do any thing with the remainder, or just don't worry about it since it will be in the 1000ths position and I really don't need to worry about that for my application? Sean Breheny wrote: > Hi John, > > Please give some more info. Are you using this in a high-level language > (such as C)? > > I would suggest that you do one of two things: > > #1) Multiply all numbers by some constant (best for it to be a power of 2, > like 1024) to begin with,do your math,then divide the result by the same > constant. The quotient is the part to the left of the decimal,the remainder > is the part to the right of it. I believe this is called fixed-point math. > > #2) Use floating point math routines. > > If you are using numbers with a small number of digits and the range > doesn't vary much (i.e., you work with numbers from 0 to 200 and only need > xxx.xx precision), use method #1. It is MUCH faster. You can use shifts to > do the multiply and divide by the power of two at the beginning and end. > > If your number range is variable (i.e., you work from .0001 to 1 billion, > and need x.xxxxx * 10 ^ e type numbers), use #2 > > Sean > > At 04:10 PM 11/7/99 -0500, you wrote: > >I have a formula K*(T1-Zacutal)/T2actual > > > >where K is a constant = 4*Bit Scale Factor (like 255 bits from 50% duty > >cycle to 100%) > >T1 is the high time of the PWM during normal operation > >Zactual= Zcal*T2actual/T2cal. > >T2actual is the PWM on time during normal operation. > >Zcal is T1 during calibration. > > > >When I do the multiplication, division and subtraction of the above > >numbers I begin to loose the fractional numbers, like 28.456 turns into > >28. This can be a problem especially at values near 0. I always get 0 > >for my calculation when I should have something like .5. > > > >Does anyone know or have references to multiplication, division and > >subtraction routines that do not loose the decimal. I have seen > >routines that give a remainder but then I don't know how to use the > >remainder in the arithmetic operation. > > > >Thanks > >John > > > | > | Sean Breheny > | Amateur Radio Callsign: KA3YXM > | Electrical Engineering Student > \--------------=---------------- > Save lives, please look at http://www.all.org > Personal page: http://www.people.cornell.edu/pages/shb7 > mailto:shb7@cornell.edu ICQ #: 3329174