Is the loss of precision that important? You may be able to get a little more precision by first dividing by 64, then multiplying by the 0-45 advance figure and then dividing by 16. Any chance of putting on a web site when it's finished? Regards Mike Rigby-Jones > -----Original Message----- > From: Mark Crankshaw [SMTP:mic1000@HERMES.CAM.AC.UK] > Sent: Thursday, May 20, 1999 1:01 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Slightly [OT] Timing calculations > > As part of an engine ignition project I need to calculate an advance value > using a lookup and a measured RPM. Seems simple enough but I've come > across a small problem. > > The time for 180 degrees of crank rotation is measured giving a 16 bit > number which is used in a lookup to give an 8 bit advance number > corresponding to a range of 0-45 degrees of crank rotation. This number > then must be converted into time, based on the RPM to feed into a delay. > > The numbers look friendly - dividing the 180 degree time by 4 gives the > time for 45 degrees, dividing that by 256 then gives the time for an > advance number of 1 so then just multiply by the advance number. Since the > division is by 1024 overall, I intended to just shift the bits right, > saving a slow division routine. The problem with the 'divide by 1024 and > multiply by advance value' process is that a lot of the precision is lost > if I divide by 1024 first. Multiplying by the advance number first would > require 24 bit maths routines. > > Anybody got any cunning ideas? The calculation must obviously be quite > quick > > Thanks, > > Mark.