Rotaru encoder with PIC microcontroller?


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2011
    Location
    Skopje,Macedonia
    Posts
    71

    Default Rotaru encoder with PIC microcontroller?

    I was wondering how to conect a rotary encoder with PIC microcontroller.How should I do that?For example with PIC16F876A.

  2. #2
    Join Date
    Aug 2004
    Posts
    34


    Did you find this post helpful? Yes | No

    Default Re: Rotaru encoder with PIC microcontroller?

    If your encoder is working with 5V , you can connect it direct to any port. But pls. remember you have to connect only the A and B outputs of that encoder. Of course if you want to check also the directions. If you want to measure rpm with that encoder you can connect also the Z output which can give you one puls on each turn.
    If you check the A and B outputs by one oscilloscop you will see that there are phase difference between signals coming form that outputs. That difference is used to find out the turning direction. The output gives you the following information;
    (%BA) ; %00 - %01 - % 11 - %10
    You can use the following code example for finding the turning direction;
    1- Read the A and B (let say it is %00) ,OLD=%00
    2- Read again the A and B NEW=%00,
    3- IF OLD=NEW THEN GOTO 2 'it means there is no turn on the encoder
    4- Let say the NEW is %01
    5- DIR=Old.0 XOR New.1 ( make XOR the bit0 of old and bit1 of new)
    6- If DIR=1 the direction is (let say) clockwise Else is counterclockwise.
    7- IF DIR=1 then DISTANCE=DISTANCE+1
    8 - ELSE DISTANCE=DISTANCE-1

    It will be better if you use the PORTB.4- PortB.7 change interrupt. Byte way you do not need to wait and look if the encoder is turning or not.
    Connect A to PortB.4 and B to PortB.5 and open the interrupt.
    I hope you have understood.

    Ero

  3. #3
    Join Date
    Jan 2011
    Location
    Skopje,Macedonia
    Posts
    71


    Did you find this post helpful? Yes | No

    Default Re: Rotaru encoder with PIC microcontroller?

    I don't know how to use interrupts.For that you're saying in the post up there.Can you post a code with example in PBP?I don't want to use for RPM counter,I have a mouse (from old PC) and I want to use it.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts