I have interfaced a 200 line count QD145 optical encoder to a DL06 PLC. The PLC’s inputs are set up in high speed mode to receive the incremental quadrature pulses coming from the optical encoder.

.

CT174, the designated high speed up/down counter is used to interface to the encoder. By default inputs X0 and X1 are used for the A& B incremental signals, without having to code them to the counter. Input X2 is designated as the reset, and may normally be connected to the index pulse of the encoder.

Since frequency is “cycles per second” we set up our high speed timer on rung three to give us a count total every second; this is our frequency.

Rung four is where all the heavy lifting happens:

After the high speed timer has timed out to one second, we load the PLC’c accumulator with the value from the counter (CT174). This will be our frequency, or the number of optical encoder counts that we have accumulated in one second.

We then multiply that value by 60, which uses our one second total to convert to the number of pulses occurring in a minute.

And we divide that total by 200, the line count, to get the RPM of the optical encoder.

We move the value to V2500, a location that we can pick up with the screen.

C3 is then used to reset the timer and counter and start the process over again.

I have interfaced a 200 LC QD145 to a DL06 PLC to show how to convert from a line count to mechanical degrees. This type of conversion may be useful for any application needing to know an angular measurement.

To calculate a degree measurement we divide 360 by the line count to get the number of degrees per pulse.

(360 Degrees /200 Pulses per revolution) = 1.8 Degrees per pulse.

The High Speed counter we have set up will automatically add one to it’s running total any time the encoder is rotated counter-clockwise, and subtract one from the running total any time the optical encoder is rotated clockwise.

This value is loaded into the PLC’s accumulator and multiplied by 1.8 (K18) to convert to degrees. The number is then outputted to an address(V2500)that we can display on the screen.

When the index (Z) pulse occurs, we reset the counter to let it know we are back at zero.

Below is the PLC code for the pulses to degree conversion.

It is good to note that the PLC is set up to retain the count value when powered off, but if the optical encoder is rotated during this time, the count will not change and the value at power up will be different than the encoders real world position.

It is good practice to rotate an incremental encoder/optical encoder on power up until an index pulse is seen and start counting from there. This is technique is known as “homing”.

By default the quadrature counting mode within the PLC keeps track of negative numbers, so we are able to accumulate a negative degree value depending on the direction of rotation after zero. While this may seem a bit confusing, it is really just a matter of your point of reference. –90 Degrees is the same exact point as a positive 270 Degrees. If we wanted to convert to where we stayed within a positive degree range, you could change the PLC code to add 360 to the measured value any time it went negative.

I have interfaced a QD145 200 Line Count Optical Encoder to a DL06 PLC and set up the PLC for mode 20 ‘High speed Up/Down counter’.

Here is a video of Optical Encoder Counting:

Below is the ladder logic code for programming the PLC to count pulses from the QD145 optical encoder using high speed counting mode. Note that “high speed” for the DL06 standard inputs is still limited to 7kHz. Where the encoder can go as high as 500 kHz by specification.

Setting up the ladder logic code for the DL06 is fairly straightforward in that the UDC (up down counter) seems to be built to take optical encoder inputs.

When in high speed mode, inputs X0 and X1 are inputs to the counter (CT174) by default. Input X2 is a reset input and could be wired to the index channel on the optical encoder if we were looking to translate the count into a 360 Position, but is left unwired for this up down count application.

The first rung on the counter (CT174) is the ENABLE. I latched C11 off of the first scan bit (SP0) to enable the counter. Note that CT174 was not picked arbitrarily, it is the specified counter location for high speed counting

The use of X0 and X1 on the second rung of the counter may seem a bit odd if you thought they were feeding counts the counter; instead those inputs are being used to updated the count from the input buffer to the counter memory location. To ensure that we always have the most accurate information. I place the two inputs parallel to trigger the update whenever we see a pulse from A OR B. This rung could also be held on for constant updating.

I am using bit 2501.0 (the F1 Key from the panel) to force a reset on the counter when ever the button is pressed.

Bit 1175.15 is the MSB from counter CT174 and indicates when the count has gone negative.

I set up a QD145 optical encoder on a Direct Logic DL06 PLC with some simple ladder logic to determine direction based on the A and B incremental inputs.

below is a video of the optical encoder in action:

In the PLC I used (DL06), the inputs are filtered, which makes the response time very slow and limits the RPM that can be read. Please note that you will always need to take into account the maximum input frequency of your PLC when interfacing to an encoder.

Also please note that this code was set up for demonstration/learning purposes only and has not been tested in a feild application.

The first two rungs of ladder logic are used to lock direction after it has been determined from the optical encoder.

Inputs X0 and X1 are the respective A and B signals from the QD145 optical encoder.

outputs C0 and C1 are used to latch direction, which is determined by the next high pulse after both signals go low ( Latch C4) .

Rung three is used to latch when both channels are low. This a penultimate point in that the first signal to go high after this latch is set tells us the direction of the encoder.

Rungs four and five drop out the current direction latch when a direction change occurs.

Rung six is used to reset the low latch. If we don’t have this, the program will permanently latch into the first direction is sees.