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
    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 ?)

    Oh, in that case there's no need for the 18F2431, it would be overkill.
    Set one of the PICs timers up as a counter and feed the pulses from one channel to it, then read its value at precise intervals and you have the velocity. Or use the Count command to Count pulses for a certian amount of time. Or, instead of counting pulses, use the capture module to measure the length of ONE pulse. Or use PulsIn to do the same thing, or.....

    /Henrik.

  2. #2
    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 ?)

    Hahaha, yes indeed 18F2431 would be overkill

    Okay, the issue with rpm is clearer now, but what about direction ?

  3. #3
    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 ?)

    Like I said earlier, read the state of channel B at the rising edge of channel A and you have the direction.

  4. #4
    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 ?)

    Quote Originally Posted by HenrikOlsson View Post
    Like I said earlier, read the state of channel B at the rising edge of channel A and you have the direction.
    i am not quite clear about it, is it something like this ? :

    porta =00000001 direction is clockwise
    porta =00000010 direction is counter clockwise

    what happen with the direction WHILE the encoder is rotating ? wouldn't it be changing constantly ?

  5. #5
    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 ?)

    The two signals are 90 degrees out of phase in relation to each other. This is what it looks like:
    Name:  Encoder output.JPG
Views: 1011
Size:  18.2 KB
    When the encoder is rotating "forward" (ie you're going left to right in the above picture) channel B is low at the rising edge of channel A. When the encoder is rotating "backwards" (ie you're going right to left in the above picture) channel B is high at the rising edge of channel A. So, you need to detect when channel A goes from low to high and then read channel B.
    Code:
    WHILE ChannelA_Input = 1 : WEND   ' Wait for channel A to go low if it happens to be high
    WHILE ChannelA_Input = 0 : WEND   ' Now wait for the rising edge of channel A
    Direction = ChannelB_Input           ' If channel B is high we're moving in one direction, if it's low we're moving in the other
    The above code obviosuly presents a risk of hanging if the velocity happens to be 0 or very low but you get the idea.

    /Henrik.

  6. #6
    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 ?)

    Quote Originally Posted by HenrikOlsson View Post
    The above code obviosuly presents a risk of hanging if the velocity happens to be 0 or very low but you get the idea.
    I thought about that , but I worried about DT-INT would block it in the process

    is it possible to put this in-line with speed detecting process ?

  7. #7
    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 ?

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