Hej Dennis Plunkett. Tack fšr ditt meddelande 11:42 1999-10-06 +1000 enligt nedan: >This routine has the problem in that all possible changes of state for the >same direction produce a GOTO to the same routine, That is perfectly configurable: just fill in in the table, it has entry for *all 16* possibilities: forwards: all four changes backwards: all four changes no changes: all four unchanged states errors, both pins changed: all four ways > the function still needs >to know when a full cycle has been completed i.e. One full revolution Encoders use to have between 32 to several thousands cycles per revolution. If you want perfect synchornization to a 0¡ sync signal, set the two gotos that you wish will count into the zero position to point to specialized count up/down routines that also checks the sync signal. This will give the best possible zero position synchronization, with a resolution of four steps per cycle, making the most out of the encoder. >, this >may be done by running a counter. Also the routine must see all chages of >state else an error is encounted. Of course, if it misses one change, how can you be sure it did not miss more changes. This is *required* for safe machine positioning. If it just is reading a knob on a panel: ignore the overspeed. > On a quadrature cycle only looking for a >complete rotation, the software only needs to check one line. That is wasting resolution. By detecting all four changes per cycle, the resolution for a 128 cycle encoder is 512 steps per revolution. And only detecting one line makes overspeed error detection impossible. Using interrupt on change for the two lines is the best. If you need to poll for changes instead, we we might want to add a few lines of code before my example that just check if any line has changed, thus minimizing the cycles needed when no change. (but will add total cycles when a change has occurred) >I hae included a high level respone to this, the code produced is not very >efficent and you can clean it up to make it faster, just done so that >people can see what I am on about Sorry, I have not learned C... still yet. PS I could also add "2-bit gray" to the subject.. how many names do this device have? ;) DS /Morgan Morgans Reglerteknik, HŠllekŒs, 277 35 KIVIK, SWEDEN tel +46(0)414-446620, fax -70331, mrt@iname.com