Calculate Distance Using Rotary Encoder


Closed Thread
Results 1 to 18 of 18

Hybrid View

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

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

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


    Did you find this post helpful? Yes | No

    Default Have read the asm examle by Luciano

    Hi there,

    When you are turning the rotary encoder slower you get good results:

    Reason : Your loop has enough time to "PAUSE" or "LCDOUT" and does not miss pulse.

    When you are turning the encoder faster:

    It is missing pulses while you are doing other tasks. It is always reliable to use an asm interrupt. No other way out perhaps.

    Regards

    Sougata

  4. #4
    Join Date
    Nov 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sougata
    Hi there,

    When you are turning the rotary encoder slower you get good results:

    Reason : Your loop has enough time to "PAUSE" or "LCDOUT" and does not miss pulse.

    When you are turning the encoder faster:

    It is missing pulses while you are doing other tasks. It is always reliable to use an asm interrupt. No other way out perhaps.

    Regards

    Sougata

    Can anybody tell me how to use ASM interupt. What are the advantages? TQ

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


    Did you find this post helpful? Yes | No

    Default Can you post the full schematic

    Hi,

    I do not have a 16F877A lying around still I would try to one. I basically design with PIC18F452. The memory bank is different than 16F877A. At least I will try to simulate it.

    Regards

    Sougata

  6. #6
    Join Date
    Nov 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    I think you can just post the code because I just wanna some idea....TQ

  7. #7


    Did you find this post helpful? Yes | No

    Default aliasing

    You need to UP your sample rate or use interrupts (on change) to prevent aliasing.

    If you MUST display the current values on an LCD, I believe you'll need to use interrupts as others have said.

    I'm currently working with an encoder with 50 slots, rotating at 1rps (200 positions per second in grey code) and need to sample at <1mS to ensure no errors. This is because there are no absolute guarantees that each of the 4 phases (codes) are equal in length, due to quality control issues with soldering and placement of the LEDs and Photodiodes. Thus, although technically you expect 200 codes per second in this scenario, "normal" oversampling rules dictate 2x that sampling rate, and the error factor that I'm encountering with component placement suggests 5x instead. If you cut your sampling time back, or miss one of these, it can result in an incorrect count.

    Thus you're pretty much bound to use interrupts: either on change, or on timer to sample (change is more efficient for obvious reasons).

    -------------Picster-----------------------

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