read encoder from lpt port using vb 6.0


Thread Starter


Hi I am a rookie in this application. I have 2 motors with 1200 ppr and I need to know the code to read it. Also I need to know to increment and decrement the count. tq

Robert Scott

What do you mean by increment and decrement the count? If you want to read an encoder, then you will be just reading something. In any case, you don't use the lpt port to read an encoder. You need a plug-in board that has a quadrature encoder interface. The manufacturer of the board provides the software interface to VB.

Robert Scott
Real-Time Specialties
Embedded Systems Consulting

Davis Gentry

Among other things, reading an encoder directly through a parallel port would be VERY difficult, and impossible if the encoder was changing state at any speed at all. You need read times down in the low nsec to even think about catching every count. Then you have to decide if the A channel is ahead of the B channel or vice versa in order to get direction.

You have 1200 ppr (I am assuming you mean counts per revolution rather than lines - if you mean lines then the total counts goes up by a factor of 4). So if you are moving at 1 rps then you need to be able to accurately read each input 2400 times per second at a minimum - preferable more like 12000 if you actually want to get an accurate velocity from the encoder and control the motor. Since timers in VB have a theoretical minimum of 1 ms, an a real world minimum of something like 10 ms (but don't rely on that - every time someone touches a mouse the actual time spent will increase) you can get only 100 reads per second.

Use dedicated hardware for counters, then pass the totals to the pc across the parallel port. Note that even doing it this way you will have problems controlling the motor. For position loop you should be looking at an absolute minimum of 1kHz.

Davis Gentry
Delta Tau Data Systems