On Thu, 12 Jun 2008, Snail Instruments wrote: > At 09:26 PM 6/12/08, you wrote: > >The speedo wants 2,458 pulses per kilometre. This works out at dividing > >the wheel sensor frequency by about 2.367 with a maximum frequency from > >the wheels of 320Hz at 150MPH (no I don't plan to go that fast! Might as > >well design to the max speed though). > > Express the 1/2.458 as a fractional binary number: > > = 0.0110 1100 0010 0111 etc... or = 0.6C27 in hexadecimal > > Now make a 16 bit variable, add 0x6C27 to it for every incoming > pulse. Every time there is a carry set after addition, send an output > pulse. The division ratio will be very close to 2.367 without large tables. This a good way of doing it and in case anyone is wonder how to derive the magic number: 0x10000 * 1 / 2.458 = 0x6C27 If you wanted greater accuracy, say 24 bits instead of 16 0x1000000 * 1 / 2.458 = 0x6C275E Regards Sergio -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist