quad encoders


Closed Thread
Results 1 to 1 of 1

Thread: quad encoders

  1. #1
    Join Date
    Aug 2005
    Location
    NC, USA
    Posts
    53

    Default quad encoders

    Hi. I have gotten a quad endcoder working using a similar approach to this thread http://www.picbasic.co.uk/forum/showthread.php?t=778

    The issue I am having is I am not clever enough to elimnate the while end statement. The issue is if the encoder is not moving I do not want it to wait. I need to be doing other "quick" tasks then continue looking for a change. I also need to add another quad encoder, so it can not be waiting on one while missing all the counts on the other. The encoders are not moving fast and are only 128ppm so speed is not a huge issue and I do not have access to the timers, nor do I have enough for two quad encoders.

    here is my code thus far...

    start:
    if P1 = 1 then 'wait for button push
    HIGH LX1 : low LX2 'led green
    else
    low LX1 : high LX2 'led red
    countsx = 1000 'junk number for now
    countsy = 1000 'junk number for now
    debug 10,13,"Start...",10,13 'debug statements to be removed to speed up later
    'will put a command to drive a motor here
    repeat
    gosub sub_count
    until (countsX >= (1000 + 128 * 10)) or Estop = 0 'want to count Y axis too on another encoder
    'will stop motor here, recount during drift, adjust motor, etc.
    endif
    debug "X: ", dec countsx, " ", 13

    goto start

    sub_count:
    'right now just looking at x axis encoder. Need to look at y axis at same time
    OldPosx = (PORTB & %00011000)>>3 ' get only PORTB<3:4> bits
    NewPosx = OldPosx
    while (NewPosx==0) or (NewPosx==3)
    'program hangs here if not moving.
    'tried an if then, but the oldposx keeps getting reset so it does not work
    'cant figure out a clever way to remove this loop without missing or counting too much
    NewPosx = (PORTB & %00011000)>>3 ' get only PORTB<3:4> bits
    wend
    Newposx = newposx ^ oldposx
    select case newposx
    case 1
    countsx = countsx + 1
    case 2
    countsx=countsx - 1
    end select
    return
    Last edited by cpayne; - 13th March 2007 at 18:51. Reason: typo in title...

Similar Threads

  1. decoding quadrature encoders
    By ice in forum mel PIC BASIC Pro
    Replies: 93
    Last Post: - 28th February 2017, 10:02
  2. Quick thoughts: DT Ints with encoders
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 7th January 2010, 02:01
  3. Rotary encoders
    By mister_e in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st February 2007, 17:57
  4. Quad encoder problems
    By smitty505000 in forum mel PIC BASIC Pro
    Replies: 51
    Last Post: - 5th October 2006, 23:44
  5. Double (or Quad) Precision and FP math
    By NavMicroSystems in forum PBP Wish List
    Replies: 1
    Last Post: - 24th January 2005, 20:25

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