Hej Matthew Ballinger. Tack fšr ditt meddelande 22:22 1999-10-02 -0400 enligt nedan: >In a message dated 10/2/99 3:46:23 AM Eastern Daylight Time, >morgans.rt@TELIA.COM writes: > > > Matthew Ballinger wrote: > > > Or a much more efficient routine > > Yes less instructions, but I have hard to see if it can beat an "addwf >PCL" > > in decode speed, once the input bits are retrieved, and we also have to >store > > them for next time. > > But I will try your suggestion too. > > > > >would be (in parallax mnemonics): > > >ChkEncoder mov new,encoder ;move the ra port the new var > > > and new,#00000011 ;clear all but encoder bits > > > mov temp, new > > > xor temp,old ;is old and new same? > > > jz :Return ;if so quit > > > clc ;clear carry > > > rl old ;shift old to align old.0 with >new. > > 1 > > >bit > > > xor old,new ;xor bits to determine direction > > > jb old.1,:up ;if bit is 1 then up (CW,etc), >if > > bit > > >is 0 then down (ccw,etc) > > > > And then wee need to rotate the other way to align the other bits and xor > > them to see if it was up. > > And if neither up or dn, and not same, both bits changed = overspeed or > > error. > > > > Did I get it right? > > > Not quite. *Everything* is taken care of with this code. >1.If code jumps to :return , then no change in posistion was made. >2.If the final xor produces a 1 then the encoder went CW >3.If the final xor produces a 0 then the encoder went CCW >Nothing more to do. Well.. To be safe, the routine has to detect also when both phases has changed (180¡ cycle rotation since last time) This will indicate overspeed or hardware error, noise or other error. W often has to now when/if the routine fail so we dont tahe an erroneous cont for correct, especially in machine positioning... >Ok, well, add 1 instruction to store the old bits (oops). >Speed doesn't really suffer either. I'll count the instructions though to be >sure. You may be right. Take in count that parrallax macros often is more than one instruction. goto table method cycles: First get two phase bits into the same byte as the old ones, by rotating them into the storebyte (the previous phase bits then is in bit 2 and 3, and the now new bits will be used as old next call) : Total 8 cycles movf storebyte, W 1 cycle andlw b'1111' 1 cycle addwf PCL ,f 2 cycles ... goto appropriate_routine 2 cycles ... Making total 14 cycles, isosynchronous, including jump to appropriate routine (count up/down/error/nochange) We may shave off two cycles by redesigning so we have 00xxxx00 to add to PCL, so every entry in the goto table then can be a small routine upto 3 instructions + "goto nextinterruptservice" Save cycles, but wastes a lot code space. regards /Morgan >Matt Ballinger Morgans Reglerteknik, HŠllekŒs, 277 35 KIVIK, SWEDEN tel +46(0)414-446620, fax -70331, mrt@iname.com