Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Function of terminals in rotary encoder

Status
Not open for further replies.

agus

Newbie level 4
Joined
Jul 20, 2005
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,386
hai....I have a question about rotary encoder. I not really understand about the function of three terminal A,B and Z of encoder. From reading, I found that terminal A and B is used to determine the rotation of the shaft either in CW or CCW. What is the function of A terminal.

From my understanding, the number of output pulse from the rotary encoder is depend on setting of encoder configuration in programming language,eg VC++.
How many type of function is prepared to set the configuration of the rotary encoder.

Thank you. Please correct my understanding if I am wrong.
 

Re: rotary encoder

If you have only one wave, and you know the meaning of a length of a pulse, you will be able to calculate a distance. However, you don't know which direction you are travelling.
If you have 2 waves, A and B, for example, which are shifted by 90°, you can not only calculate the travelling distance by using any of the waves: A or B, but by analizing rising or falling edges of these waves you can distinguish the direction of the rotation.
The Z output is an additional clock wave, usually in phase with A wave, showing the window when both A and B are ON.
For reference compare the attached picture ..
Regards,
IanP
 
Re: rotary encoder

Tq khongai and IanP. The information from both of you help me a lot on understanding the basic principle of the rotary encoder. It is means that phases A and B is used to determine the rotation of the motor either in clockwise or counterclockwise. A and Z are in phase. So, for a complete one rotation of the motor is determined weither by phase A or phase Z. One more thing is about the disk. From the supplier specification is written 100pulse/rotation.Thus this value means the numbers of disk slot? It is means that the thin disk have 100 slots which is a light from LED is flowing through it. My last questios is does somebody have an experience working with rotary encoder by using Visual C++ or C++.

Thank You.
 

Re: rotary encoder

The 100 pulses/rotation means that the A (or B pulse for that matter) has 100 cycles (pulses) per revolutation (which typically means the 100 slots you mention). This means that, depending on how you decode this, that you either have 100, 200, 300 or 400 counts per revolution. Several decoding methods can be used.
(1) The simplest (100 pulses count):
- wait for the A pulse to change from low to high. If changed, then increase counter if B is low, otherwise decrease counter. Symbolically:
A: L->H if B = 0 then inc(counter) else dec(counter)

(2) 200 counts:
- as (1) but also wait for the B pulse to change from low to high. If changed, then increase counter if A is high, otherwise decrease counter. Symbolically:
A: L->H if B = 0 then inc(counter) else dec(counter)
B: L->H if A = 1 then inc(counter) else dec(counter)

(3) 200 counts:
- as (1) but also wait for the A pulse to change from high to low. If changed, then increase counter if B is high, otherwise decrease counter. Symbolically:
A: L->H if B = 0 then inc(counter) else dec(counter)
A: H->L if B = 1 then inc(counter) else dec(counter)

(4) 300 counts:
- as (2) but also wait for the A pulse to change from high to low. If changed, then increase counter if B is high, otherwise decrease counter. Symbolically:
A: L->H if B = 0 then inc(counter) else dec(counter)
B: L->H if A = 1 then inc(counter) else dec(counter)
A: H->L if B = 1 then inc(counter) else dec(counter)

(5) 400 counts:
- as (4) but also wait for the B pulse to change from high to low. If changed, then increase counter if A is low, otherwise decrease counter. Symbolically:
A: L->H if B = 0 then inc(counter) else dec(counter)
B: L->H if A = 1 then inc(counter) else dec(counter)
A: H->L if B = 1 then inc(counter) else dec(counter)
B: H->L if A = 0 then inc(counter) else dec(counter)


Obviously some variations are possible (e.g. which signal to check - one can check B instead of A ...).
The bottom line is that the software only has to detect changes in the level of the A (and/or B) signal and then increase/decrease according to the other signal. This should be not too big a problem for any programmer.
Note that you don't really nead the index pulse (Z or C), unless you need a reference signal.


Symbolical program (5) in a very crude form:

Code:
OldLevelA = readport(A)
OldLevelB = readport(B)
Counter = 0
repeat
  LevelA = readport(A)
  LevelB = readport(B
  if LevelA <> OldLevelA then
  { if LevelA = 0 then
     { if LevelB = 1 then 
          Counter = Counter + 1
        else
          Counter = Counter - 1
     }
     else
     { if LevelB = 0 then 
          Counter = Counter + 1
        else
          Counter = Counter - 1
     }
    OldLevelA = LevelA
  }
  if LevelB <> OldLevelB then
  { if LevelB = 0 then
     { if LevelA = 0 then 
          Counter = Counter + 1
        else
          Counter = Counter - 1
     }
     else
     { if LevelA = 1 then 
          Counter = Counter + 1
        else
          Counter = Counter - 1
     }
    OldLevelB = LevelB
  }
until wheareready
 

Re: rotary encoder

I also have a project using rotary encoder (but it's 1000 pulses/rotation). I have to use AT89C51 PhaseA -> P0.0, PhaseB->P0.1. Code:

if (OldLevelA && !P0.0) then
{
if (P0.1) then
Counter++
else
Counter--
}
OldLevelA = P0.0

But, misscount occurs sometime. While my encoder hasn't turn round, my uP has count. I think because of noise. How to prevent misscount occurs?
Help me plz! :|
Thx alot
 

rotary encoder

Hello Farmer,

Your algorithm is not correct. You must remember the A edge and count up or down in the B edge.
Otherwise you are not taking into account small vibration or oscilation in the encoder axis.
Supose that A is high and B is high. Small oscilation in the encoder angular position can originate transitions in A without changing B. Every negative edge of A find the B channel High, so you count up incorrectly.

Hope this helps
Best regards
 

Re: rotary encoder

Thx jorgito
I agree with u. But can u show me more detail.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top