' {$stamp bs2} ' Program to act as high speed quadrature counter ' Program Name: quadhicount.bs2 ' Last Update: Mar 10/01 tjs DIRH=%11111111 counter VAR Word counter2 VAR Word counter3 VAR Word old VAR Nib new VAR Nib direct VAR Byte ' Channel a and b of encoder go on inputs 6 and 7 in this case. quad: counter=127 'load a dummy value so can count up or down new = INB & %0011 ' get initial condition start: old = new & %0011 ' remember initial setting again: new = INB & %0011 ' get new reading IF new=old THEN again direct=new.BIT1 ^ old.BIT0 ' XOR left bit of new with right bit of old to get direction IF direct=1 THEN cw ' jump here to increment LOW 0 ' pin 0 turns led off id turning counter-clockwise counter=counter-1 ' jump here to decrement OUTH=counter.LOWBYTE GOTO start cw: HIGH 0 ' pin 0 turns on led if turning clockwise counter=counter+1 OUTH=counter.LOWBYTE 'turn on leds on pins 8 through 15 to watch count GOTO start