Measurements with an incremental rotary encoder

hello,

i am a bit new to arduino programing an i am working on a project for my wood shop. I am looking to create a DRO (digital read out) using an incremental rotary encoder. i have googled this topic quite a bit and there is not allot of info reguarding this specifically but there is plenty on doing something similar.

Right now i am having throuble grasping the idea of how i go about measureing the pulses from the encoder, specifically on how i can code it to be as accurate as possible. i have read that i want to count the riseing and falling edges of the pulses that come off of the CLK and DT lines from the encoder and to use a volatile int to store those values. i also need to determin witch direction the encoder is turning, but im still not shure how i would go about codeing that.

Is there anybody that had any expierence in this subject that could provide me with an example sketch and possibly explain why i would use a volatile int?

Google "arduino quadrature encoder" for libraries, tutorials and examples. Substitute "rotary" for "quadrature" to get even more.

JeremyRSummers:
explain why i would use a volatile int?

Look up 'c++ volatile variable'.

When it comes to quadrature encoders, you have to know how many pulses per revolution and how many revolutions per second you gonna have to deal with.

from : http://www.creative-robotics.com/quadrature-intro

Note that quadrature encoders exist for shaft rotations or linear displacement.

I worked on the code for a CNC lathe helping another forum member recently. You can find it here: CnC Person needs Arduino code Person - Project Guidance - Arduino Forum

It's a long thread, so you may want to jump to the end and just cut out the bits that read the encoders. Alternatively, reading from the start will let you see how we evolved the code from the basics, which IIRC, did start with reading encoder pulses.

thank you all for the infomation. im gonna give ot a go tonight and see what i come up with.

Do you know what the encoder is? That's very useful to know as talking to them may differ according to the output type.