I'm trying to sample an encoder every say, 20ms and get the number of = counts it has moved, in 2's complement, so it can be added to a 24 bit = register to hold the absolute position which will represent where it is = in relation to its start position. (=3Dzero) >From this I can apply limits on speed, acceleration and position, = ultimately of a servomotor, sent to it as a smoothed pulse train with = direction . (<200kHz) I'm using a 18F452 to read a HCTL 2016 quadrature decoder.=20 I can read the output bytes anytime before overflow with: bcf OE ;enable tristate output bcf SEL ;for high byte nop movf portb,w ;data from HTCL 2016 received on portb movwf d_hi ;store bsf SEL ;for low byte nop movf portb,w ;data from HTCL 2016 received on portb movwf d_low ;store bsf OE ;disable tristate output But I'd like to be able to reset the counter and get the change in = position every 20ms. So I added this, below the above and looped it every 20ms. bcf RST ;to reset counter nop nop bsf RST =20 The count is wrong, every second sample possibly, maybe due to the way = it is being reset.=20 The error which shows up on an analyser but more visibly on the LCD = attached to the PIC that reads the position register. When started from zero and moved +/- a turn-ish the LCD over-reads and = won't go back to zero when the encoder is at that physical position. When the code is used without the RST the LCD tracks the encoder = perfectly up to overflow. I wonder if anyone else has tried the HCTL 20XX family in this way and = got it to work.=20 Thanks, Brian Harris -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist