I am also interested in this problem....although I have a slightly different problem. I am a newbie to PICS, and I am attempting to design a PIC circut for reading a shaft encoder attached to a motor, and that has a really fine grain. I don't have a data sheet on the encoder....but when hooked up to the scope, I am getting a 28 microsecond pulse width, with the motor turning at the highest RPM for my application. If I don't want to miss any pulses, I need to be sampling at a rate of about 36khz (36,000 pulses per second). I have two motors I would like to monitor with one PIC. What I would like to do, is have the PIC pull in the shaft data, and keep track of it, and then deliver it over a serial line when asked for the totals. What would be the best PIC for doing this? I want to make sure my clocking is fast enough that there is no chance of missing a pulse. Thanks, - Ted -----Original Message----- From: cdb [mailto:bodgy1@OPTUSNET.COM.AU] Sent: Thursday, April 17, 2003 9:10 PM To: PICLIST@MITVMA.MIT.EDU Subject: Re: [PIC]:Optical Encoder and PICs On Thu, 17 Apr 2003 08:01:48 -0400, Mccauley, Daniel H wrote: was wondering if anyone had experience of using an optical encoder (A and B inputs for quadrature mode) on a PIC microcontroller. I'd like to use the A and B output of the optical encoder and tied into PortB and have each pulse (either on A or B) trigger an interrupt. I don't with an optical version, but here is some code in 'C' that you can play around with. See also another incarnation elsewhere in last weeks archives, where I had a counting problem with my original code. //EncoderA_pin on PORTA: 1. B_pin on PORTA: 0 //This checks for the sequence 10->11 for CW pulses and 11->01 for CCW. void getenc() { if (!bRA0) //enc_B is low old_enc_state=1; //make flag high //we get here if both enc_B is now high and old assumed state was high if ((bRA0) && (old_enc_state)) { if (bRA1) //If enc_A is now high we have gone from 10->11 in pulses { enc_state=1; old_enc_state=0; flag now low so that we have to wait for the next 11 to come around } if((!bRA1) && (old_enc_state)) { enc_state=-1; old_enc_state=0; } } else { enc_state=0; //here if there was no change in encoder position } } Colin -- cdb, bodgy1@optusnet.com.au on 18.04.2003 I have always been a few Dendrites short of an Axon and believe me it shows. Light travels faster than sound. That's why some people appear bright until they speak! -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics