Today is...
Wednesday, May 23, 2018
Welcome to, the global online
community of automation professionals.
Featured Video...
Featured Video
A demonstration of EtherCAT control of linear motors using the CTC EtherCAT master.
Our Advertisers
Help keep our servers running...
Patronize our advertisers!
Visit our Post Archive
Encoder program example
need some examples for encoder positioning and rotation direction

i am connecting a quadrature encoder to my plc but i cant understand that how to write program for it. i want to sense 1)position 2)rotation direction

I once had a similar problem.

Here are several questions. Answering them will help guide your thought processes, and resubmitting your request with as many of them answered as possible will help those who would want to assist you further.

First, identify what brand and model PLC you have.
If applicable, what encoder module are you sending the encoder signal to?

If instead, you are connecting them to several of the PLC's generic DC inputs (can be done; but there are several pitfalls, and its usually a lot
more work) are they fast enough to read the encoder at it's intended maximum rotational shaft speed? What is the encoder power supply voltage?
How many output pulses are generated per revolution?

Is the encoder simply A and B quadrature (two pairs of signal leads), or is there a marker pulse as well (three pairs of signal leads)? What 'position' is it you want to read? For instance, if the encoder is connected in some fashion to a table that does a linear move, and you want to use an encoder to feed back how far that table move is (in inches, mm, whatever) then you'll need to do some scaling as well (x number of pulses per linear unit).

Read the applicable PLC manuals. Often, they will have snippets of ladder logic to help explain how to do the programming. When thinking about what
programming to write, consider "A). what is the least amount of programming needed to verify encoder operation", and "B}. what do I want this to eventually be capable of doing". Do "A" before "B"; attempting them in reverse order often leads to frustration.

After you've done these things, and think you have a shot at it, connect the encoder to the PLC, and write enough of a test program to see if it reads
pulses. Go through several DRR (debug, re-analyze, re-write) cycles until you get the basics, then add other stuff (endstop limits, pulse count-to-linear distance scaling, etc) to the test program, and DRR those. Eventually, you'll have the guts of a working program, and will have
answered many of your questions.