On Thu, Nov 16, 2006 at 06:58:32PM +1300, Brian Harris wrote: > I've got a modulo arithmetic question to do with a sensor > outputting data like this: > > bits 31-26 ID and parity > bits 25,24,23 modulo counter > bits 22-0 data (LSB bit = 42.91534 micro degrees) > > The 3-bit modulo counter increments when crossing from 359 to 0 deg > and decrements when crossing from 0 to 359 deg. > > I want to find the difference between the current reading of the sensor > and the previous reading. > Using the the least sig bit of the modulo gives angle polarity but only > for the rollover between +-360deg. It looks to me like what you've really got is a 26 bit angle - the "modulo counter" bits are just the higher bits of the angle. Can't you just subtract the two 26-bit values and look at the sign to work out which direction it's moved? Chris -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist