On 1/17/2014 12:30 PM, Jon Hulatt wrote: > I definitely will try assembly once I have the logic figured out. I wrote= the above code and I just have this niggling doubt that that is the best w= ay to do it, i wonder if i=92m missing some major optimisation or something= .. > >> Your code aside, if you're looking for speed maybe you should be writing= it in assembly? Counting quadrature tachometer signals requires the OLD data as well as=20 the NEW data, cleaned up to prevent random errors from noisy contacts. 1. read the tachometer data repeatedly until the data is identical to=20 the previous read; this eliminates noise from the system. 2. combine the LAST two bits and the NOW two bits to form the address of=20 a 16-position jump table. ONE of the addresses means down-count and=20 another means up-count; which one depends on how you have organized the=20 data. The other 14 addresses are meaningless so are simply ignored. 3. I would interrupt on ANY data change by the two bits, by using the=20 INT ON DATA CHANGE function of most PICs. The faster you can sample the data the faster the speed of the shaft can=20 be read, so your PIC needs to run as fast as possible and be written in=20 assembly. BUT you can write in C or whatever to verify your approach. its more complex than it looks. -- Bob Axtell The only place success comes before work is in the dictionary. VINCE LOMBARDI --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .