> > The tricky part is doing low pass filtering > > on circular values. > > Yes, that does sound tricky. Tell us how you do it, OK ? I have only had to do this a few times, and I could always arrange the internal representation of an angle so that a full circle was 8**N, with N typically 2. In other words, use a 16 bit unsigned number to represent the angle with 2**16 representing a full circle. That way the number automatically wraps right where the angle wraps back to 0 anyway. For example, 0 is 0 degrees, 1 is 1/65536 = .0055 degrees, and 65535 represents 359.9945 degrees. I find it easier to think in units of full circles than degrees in these cases. Once you have the representation right, from 0000h to FFFFh for example as above, it is a matter of sometimes adding 10000h to a number before using it in a filter operation. Note that adding any multiple of 10000h doesn't change the angle. It's like saying 370 degrees instead of 10 degrees. You adjust at most one of the numbers in the filter operation so that the gap between them numerically is never more than 1/2 circle. For example, the two angles F123h and 0123h are really very close (about 1.4 degrees), but you don't want to just average the number numerically because you end up with 7923h, which is almost half a circle from either angle. In this case, add 10000h to 0123h, you can now average F123h and 10123h just fine. Just truncate the result to 16 bits and you always end up in the first circle. ******************************************************************** Olin Lathrop, embedded systems consultant in Littleton Massachusetts (978) 742-9014, olin@embedinc.com, http://www.embedinc.com -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.