Calculate Distance Using Rotary Encoder


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Sorry, I'm still not clear about using interupt. Please give me more details. TQ

  2. #2
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Post your exact problem

    Hi,

    What is the maximum expected rotation per second. And with your current setup what are you exactly experiencing.

    Regards

    Sougata

    Wishing a speedy recovery of our forum member Steve who is hurt in a car accident.

  3. #3
    Join Date
    Nov 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    maximum rev / sec is 20 rps. I'm currently running a line tracer robot. I wanna know how far the robot can go. TQ

  4. #4
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Use Instant Interrupts by Darrel

    Hi,

    I understand that you are new to using interrupts but everybody has a first time so go ahead. This forum will always be beside you. Here http://www.picbasic.co.uk/forum/show...ant+Interrupts you will find more information. To learn more about how to setup the interrupts, read the datasheet carefully. Enable global interrupt and portb.0 interrupts (your encoder should be connected here), also set the Interrupt edge as per your encoder. Now when you are in the ISR just increment the counter variable. You should check overflow of your variable or use a comparison to increment a pulse/meter (another variable). It is sure you will find problems but do write some code and test.

    Good Luck

    Sougata

  5. #5
    Join Date
    Nov 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    I try using this code. But only get forward and backward only. The value of pulse is totaly depend on rotation per second. How I need to maintain pulse / rotation regardless how fast I rotate the encoder. So the distance are varies depend on speed, although the distance is same. Please help



    DEFINE LOADER_USED 1

    ' Define LCD pins
    Define LCD_DREG PORTD
    Define LCD_DBIT 4
    Define LCD_RSREG PORTE
    Define LCD_RSBIT 0
    Define LCD_EREG PORTE
    Define LCD_EBIT 1
    define PULSIN_MAX 200
    ADCON1 = 4 ' Set PortA 0, 1, 3 to A/D inputs

    old var word
    new var word
    dir var byte
    cnt var word ' pulse/rotation

    Encoder: ' Routine to read rotary encoder
    old = PortB & %00000011 ' Read PortB.0 and PortB.1

    pause 2 ' Add some time between reads
    new = PortB & %00000011 ' Read PortB.0 and PortB.1


    if old = new then goto Encoder ' If old and new equal, read again

    old = old & %00000001 ' Only need PortB.0

    new = new >> 1 ' Only need PortB.1

    dir = old ^ new ' Dir equals PortB.0 XOR PortB.1

    If dir = 1 then ' If Dir = 1 then...
    cnt = cnt + 1 ' ...Count up
    else ' Otherwise
    cnt = cnt - 1 ' ...Count down
    endif ' End If statement
    Lcdout $fe, 1 ' Clear LCD screen
    Lcdout #cnt ' Display Hello
    Lcdout $fe,$C0, 1 ' Clear LCD screen
    Lcdout #dir
    pause 10
    goto encoder ' Do it forever (I hope)

    End

  6. #6
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    Hi,

    See this thread.
    http://www.picbasic.co.uk/forum/showthread.php?t=1552

    Read all the posts first.

    Best regards,

    Luciano

  7. #7
    Join Date
    Nov 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    I was so wonder by counter result is deferent. When I turn the encoder slower I get more count and when I turn the encoder faster I get less count. Count refers to variable cnt. Can someone explain?

    ------code--------------

    old var word
    new var word
    dir var byte
    cnt var word ' pulse/rotation

    Encoder: ' Routine to read rotary encoder
    old = PortB & %00000011 ' Read PortB.0 and PortB.1

    pause 2 ' Add some time between reads
    new = PortB & %00000011 ' Read PortB.0 and PortB.1


    if old = new then goto Encoder ' If old and new equal, read again

    old = old & %00000001 ' Only need PortB.0

    new = new >> 1 ' Only need PortB.1

    dir = old ^ new ' Dir equals PortB.0 XOR PortB.1

    If dir = 1 then ' If Dir = 1 then...
    cnt = cnt + 1 ' ...Count up
    else ' Otherwise
    cnt = cnt - 1 ' ...Count down
    endif ' End If statement
    Lcdout $fe, 1 ' Clear LCD screen
    Lcdout #cnt ' Display Hello
    Lcdout $fe,$C0, 1 ' Clear LCD screen
    Lcdout #dir
    pause 10
    goto encoder ' Do it forever (I hope)

    End

Similar Threads

  1. Quadrature encoder and ASM Interrupts. questions..
    By godfodder in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th March 2013, 14:45
  2. Rotary encoder help (not 'counting steps)
    By Elnino in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th October 2009, 22:03
  3. encoder wowes
    By wallaby in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 6th December 2005, 21:56
  4. Farnell's Rotary Encoder 733-726
    By crematory in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th October 2005, 13:51
  5. Automotive quality rotary encoder
    By d1camero in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th October 2004, 15:46

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