Quadrature encoder and loop count


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105

    Default Quadrature encoder and loop count

    After much our spend it work in interrupt's like Henrik suggest me and I am nearly finish.
    Need only one sugget more from peoples here.
    Next problem or maybe not :?
    QEI counter count in circles up/down for example 0-1999 and oposite 1999-0...in 4X mode.
    Now when I am at position 100 for example and command new position - 100 pulses motor will go to 0 and stop - OK but if maybe inertia of shaft move QEI only one step down then here is problem Setpoint is on position 0 value but QEI is 1999!
    I am little confused on how to set relation between Setpoint and QEI register of position ?
    I want to move motor to any direction with PID without limit of numbers of turn to+ or minus.
    Maybe I ned dead zero like minus limit /?
    Any suggest.
    Regards Robert

  2. #2
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Unhappy part of my code...

    Here is QEI module count set to count from 0 - 999 .
    x is number of cyrcle's of QEI module up and down.
    QEI variable is final counter..etc
    Code:
    loop: 
         z = 0
         PosHigh = POSCNTH                           'Get high byte of counter
         PosLow = POSCNTL                            'Get low byte of counter
         PosTemp = POSCNTL                           'Get low byte again  
         If PosLow - PosTemp = 0 then Goto Done      'Compare, if equal we're done.
         PosHigh = POSCNTH                           'If not, get values again.
         PosLow = POSCNTL
         z = 1 
    Done: 
         Position = POSHIGH * 256 + PosLow           'Put high and lowbyte together.
         if position > 1000 then position = 1000
         if position < 1 then position = 0 
         h = QEICON.5                                'QEICON.5 for right = 1 for left = 0 
         if PIR3.2 = 1 and h =1 then x = x+ 1
         if x <> 0 and PIR3.2 = 1 and h =0 then x = x- 1
         PIR3.2 = 0                                  'PIR3.2 maxcount transition down or up was detected
         h = 0   
         QEI =  (1000 * x) + position                    ' increment  total counter
         if z = 1 and h = 0 then QEI = QEI -(1000-position) ' dectement  total counter 
         if h = 1 and QEI = 0 then
         QEI = 65535
         endif
         if QEI > 65535 then
         x = 0
         QEI = 0
         endif
         if porta.0 = 0 then setpoint = setpoint + 1
         if setpoint > 65535 then
         setpoint = 0 and QEI = 0 and x = 0
         endif
    Butwhen I count to minus after QEI variable com to 0 if I move shaft of motor more to CCW real QEI conter will continue 999,998 and if my setpoint stay at 0 I am in big problem...
    Any suggest please
    Regards Robert

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. Calculate Distance Using Rotary Encoder
    By guanerrr in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 4th May 2012, 16:40
  3. Problem with ASM IRQ using FSR0 on PIC18F252
    By mytekcontrols in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th March 2008, 20:48
  4. Slow Opto Encoder With Interrupts
    By crhomberg in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th October 2007, 15:04
  5. Encoder problem
    By precision in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th September 2006, 22:21

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