Can PBP read optical encoder damn fast? :)


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: Can PBP read optical encoder damn fast? :)

    silly me i had the dir var as byte, it now works with this added change

    ' Encoder.0 = Ch_A
    ' Encoder.1 = Ch_B
    encoder =(porta&48)>>4

    reading the pins individually wont work for me @32mhz
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: Can PBP read optical encoder damn fast? :)

    I made that exact mistake initially, hence the comment where the DIR variable is declared - yet I missed it when looking at you code...

    I wonder why reading the pins individually doesn't work in your case. I only did it that way because CuriousOne wanted to be able to have the signals placed arbitrarily. I suspect though that reading them individually might be faster than masking and shifting.

    I've been playing around with the math to go from encoder counts to actual frequency and I'm down to 110 cycles for calculating and stuffing the bits into the array. Had to resort to a tiny bit of ASM, getting the high word of a 16*16bit multiplication back from PBP without resorting to actually using LONGs.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: Can PBP read optical encoder damn fast? :)

    encoder=0

    Warning I'm not a teacher

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: Can PBP read optical encoder damn fast? :)

    Had to resort to a tiny bit of ASM, getting the high word of a 16*16bit multiplication back from PBP without resorting to actually using LONGs.

    did you and dt make this ? , i use it if req

    ;32 bit multiply result


    A32bitVar var word[2]
    Dummy var word


    ASM
    GetMulResult macro Dword
    MOVE?WW R2, Dword ; Low Word
    MOVE?WW R0, Dword + 2 ; High Word
    endm
    ENDASM


    Dummy = 1000
    Dummy = Dummy * Dummy
    @ GetMulResult _A32bitVar
    Warning I'm not a teacher

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: Can PBP read optical encoder damn fast? :)

    Thanks, hadn't seen (or did not remember seeing, certainly can't take credit for it) that macro but that's pretty much what I did except I copied the value byte-by-byte instead of using the MOVE?WW macros.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Can PBP read optical encoder damn fast? :)

    Henrik,

    I tested your last code with a mechanical quadrature encoder and works just fine with a couple of 100nF debouncing capacitors and internal pull ups of the PIC.

    I noticed though, a jump on the position variable due to mechanical problem of the encoder. Say you are at the beginning with position at 0. One click on the right increments to 4 and one to left gets back to 0. Sometimes due to little more movement of the axis of the encoder you may get a 65535 then back to 0. This of course is not a software problem, rather a pure mechanical, but a user may perceive it as a program error.

    Ioannis

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: Can PBP read optical encoder damn fast? :)

    Yes, it's because your particular encoder has 4 counts per detent and, as you say, sometimes it will "overshoot" the detent slightly causing the code register one count before it "springs back" into the detent position. The important thing is that the code DOES register it "springing back" so that it doesn't lose position.

    These mechanical encoders exists with either 4 counts (one quadrature cycle) per detent or 1 count (1/4 quadrature cycle) per detent. Using 1x decoding with an encoder that has 1 count per detent means you'd have to turn it 4 clicks for each increment. However, with the type of encoder you have using 1x decoding might be better.

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Can PBP read optical encoder damn fast? :)

    Absolutely agree. Code works as expected and is fast enough for manual rotation. Have not tested for faster resposne.

    The encoder indeed has a detent that produces 4x pulses so yeah. It is not appropriate for that code.

    Ioannis

Similar Threads

  1. HEDS5540 optical encoder
    By louislouis in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 11th October 2016, 23:23
  2. how to read ky40 mechanical encoder ?
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 25th October 2015, 16:22
  3. Probe to read quadrature encoder with DT_INT need help
    By phoenix_1 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 31st August 2009, 20:43
  4. USB Optical mouse as motor encoder
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 24th August 2008, 15:09
  5. Damn these low power PIC and other Microcontrollers
    By keithdoxey in forum Off Topic
    Replies: 8
    Last Post: - 12th November 2006, 21:52

Members who have read this thread : 2

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