How to get encoder direction and speed / rpm ? ( with DT INT ?)


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    May 2007
    Location
    Area 71
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: How to get encoder direction and speed / rpm ? ( with DT INT ?)

    I can find direction with this code:

    A tied to portb.4
    B tied to portb.5

    Direction = portb.5 ^ portb.4
    lcdout $FE,1,DEC(Direction)


    but, the reading is NOT consistent , if I turn clockwise , Direction is not always 1 ( well , most of the time it is 1 ) and vice versa

    any tips anyone ?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,617


    Did you find this post helpful? Yes | No

    Default Re: How to get encoder direction and speed / rpm ? ( with DT INT ?)

    When doing it like that you don't "where" in the cycle you are reading the inputs.
    Since you're basically first reading one input then the other it's possible for "the other" input to change state from what it actually was when you read the first input.

    Try something like
    Code:
    Temp = PortB
    Direction = Temp.5 ^ Temp.4
    This will insure that both bits are sampled at exactly the same time.

    /Henrik.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: How to get encoder direction and speed / rpm ? ( with DT INT ?)

    Sorry to be so dumb, but I don't see how XOR'ing A and B produces a direction signal. When I try it on paper I get a new signal at double the frequency??

Similar Threads

  1. how to measure RPM and SPEED at the same time
    By teeeeee in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th July 2012, 08:34
  2. Using both hardware int and Timer Int together?
    By ozarkshermit in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th January 2010, 01:09
  3. Instant Int and encoder (Elect. Gearing)
    By boroko in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 29th November 2009, 02:29
  4. Replies: 0
    Last Post: - 7th August 2008, 09:02
  5. Can someone tell me if I am going in the right direction?
    By MatthewM in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 22nd June 2008, 15:11

Members who have read this thread : 0

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