QEI Hardware Quadrature Encoder Inputs PIC 18F4431


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Question QEI Hardware Quadrature Encoder Inputs PIC 18F4431

    I am trying to get my head around this Data Sheet, and I don't get it.
    The DS refers to A POSCNT / MAXCNT registers. Am I correct that the counts of the QE are stored in those registers MAXCNTL , MAXCNTH . . . just the same as they would be in a software variable and then I can change or clear their value with software commands ?
    And if not, where is the advantage of the QEI hardware?
    Thank You
    JS
    Last edited by Archangel; - 5th July 2011 at 04:04.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default Re: QEI Hardware Quadrature Encoder Inputs PIC 18F4431

    Hi,
    No, POSCNT contains the actual count. MAXCNT controls how "far" POSCNT counts before rolling over. That way you can have it wrap around at 1000 or 2000 or 34567 instead of 65535 if you want.

    The interrupt flag gets set whenever it rolls over, going in both directions.

    /Henrik.

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: QEI Hardware Quadrature Encoder Inputs PIC 18F4431

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    No, POSCNT contains the actual count. MAXCNT controls how "far" POSCNT counts before rolling over. That way you can have it wrap around at 1000 or 2000 or 34567 instead of 65535 if you want.

    The interrupt flag gets set whenever it rolls over, going in both directions.

    /Henrik.
    Ok, I have been looking at your answer for about 3 weeks, and it has taken most of that time to understand what you said, mostly because it addresses my problem, not my question.

    I was having "difficulty" getting MCS and PBP tp accept any input into those registers. To summarize what you posted so you know I understand, POSCNT tracks the number of changes and distance from zero counts and MAXCNT "SETS" the number of counts before rollover, almost like preloading a timer, except opposite.

    I resolved my difficulties by reinstalling MCS Pro, Oh and using POSCNTH & POSCNTL as there is no actual POSCNT listed in the P18F4431.inc . When I assemble a good working encoder example I will post the code.

    And Henrik, Thanks for the nudge !
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Re: QEI Hardware Quadrature Encoder Inputs PIC 18F4431

    Hi guys,
    I'm running into some of the same questions. From what I can tell, you can't preload POSCNTH or POSCNTL. Another item that puzzled me is that the datasheet mentions that MAXCNT value is 1527h. I can't figure out how they arrived at that figure.

    I'm trying to do as simple encoder for menu sleection and would like to set POSCNT in the middle so that I don't have to mess with rollover in either direction. I realize that it would be easy enough to deal with, but this gives me a chance to try and figure out how to use this darn feature. I'm trying to prove to myself that there is a good use for it. So far, it has been more of a pain than it is worth.

    Mark

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


    Did you find this post helpful? Yes | No

    Default Re: QEI Hardware Quadrature Encoder Inputs PIC 18F4431

    Hi,
    From what I can tell, you can't preload POSCNTH or POSCNTL
    Sure you can, I find no problems doing that.

    Another item that puzzled me is that the datasheet mentions that MAXCNT value is 1527h
    Not sure where you got that number from but MAXCNT is setable to anything between 0 and 65535.

    I'm trying to do as simple encoder for menu sleection and would like to set POSCNT in the middle so that I don't have to mess with rollover in either direction
    MAXCNTH = 128 works just fine here.

    Code:
    Test:
      HSEROUT["Program start",13]
      HSEROUT[DEC PosCntH*256+PosCntL,13]
      Pause 10
      PosCntH = 128
      HSEROUT[DEC PosCntH*256+PosCntL,13]
      PosCntL = 1
      Pause 100
      HSEROUT[DEC PosCntH*256+PosCntL,13]
    Program start
    0
    32768
    32769
    /Henrik.

  6. #6
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Re: QEI Hardware Quadrature Encoder Inputs PIC 18F4431

    Thanks Henrik,
    I'll explain a bit further: I can load POSCNTH and POSCNTL, and they show up as correctly loaded, but as soon as the encoder moves, it jumps back to 5535 and rolls to 0 from there.
    I can change MAXCNT, but that doesn't put it in the middle of the count range and avoid the rollover.

    The reason I asked about MAXCNT value of 1527h is that it is mentioned in the datasheet, on page 173, note 5, and I thought it is a strange number.

    Like I said, there are obviously ways around this, I'm just trying to understand it better.

    Thanks
    Mark

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


    Did you find this post helpful? Yes | No

    Default Re: QEI Hardware Quadrature Encoder Inputs PIC 18F4431

    Hi Mark,
    I'll explain a bit further: I can load POSCNTH and POSCNTL, and they show up as correctly loaded, but as soon as the encoder moves, it jumps back to 5535 and rolls to 0 from there.
    Then my guess is that you have MAXCNT set to 5535 and you're moving the enocer backwards from 0 (so it rolls over to MAXCNT) or you're preloading POSCNT with a value bigger than MAXCNT.

    I can change MAXCNT, but that doesn't put it in the middle of the count range and avoid the rollover.
    MAXCNT isn't there to prevent roll over. It's there to set the value at which rollover occurs. For example, if you have a 2000 counts/rev encoder you could set MAXCNT to 2000. Then you'll get an QEI interrupt for each revolution of the encoder.

    When counting up and POSCNT tries to go one count "beyond" MAXCNT POSCNT will roll over to 0.
    When counting down and POSCNT tries to go one count "below" 0 it'll roll over to MAXCNT.

    So, if you set MAXCNT to 999 then then POSCNT will count 0...999...998...997...998....999...0...1...2...3 and so on.


    The reason I asked about MAXCNT value of 1527h is that it is mentioned in the datasheet, on page 173, note 5, and I thought it is a strange number.
    That's only to show the counter action that I'm trying to explain above and that it rolls over when POSCNT = MAXCNT, which in the case shown in the datasheet happens to be at 1527h. The maximum value you can set it MAXNCT (and POSCNT) to is 65535.

    If all you want is a 16 bit counter, starting in the "middle" then try this:
    Code:
    '******************************************************************************
    QEICON = %10011000                      ' Setup QEI, 4X mode, reset on POSCNT = MAXCNT. 
    
    MAXCNTH = 255                           ' MAXCNT = 65535
    MAXCNTL = 255 
    
    POSCNTH = 128
    POSCNTL = 0                             'Set QEI counter to "center".
    '******************************************************************************
    PAUSE 2500
    HSEROUT["Program start.", 10, 13]
    
    Main:
        HSEROUT[DEC POSCNTH*256+POSCNTL,13]
        Pause 250
    Goto Main
    The counter will start at 32768, count up or down from there, roll over will occur from 65535->0 and from 0->65535 depending on direction.

    /Henrik.
    Last edited by HenrikOlsson; - 21st October 2014 at 19:42.

  8. #8
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Re: QEI Hardware Quadrature Encoder Inputs PIC 18F4431

    Henrik,
    I tried setting the MAXCNT to 65535 and already had the POSCNT in the middle. At first it rolled immediately, just like before, after one step:
    ie... 2767 -> 5535 -> 0 or 2767 -> 5535 -> 0. Then, before I posted back with another question, I thought I had better try your exact setup...
    Turns out that having it in
    INDX Reset mode (QEICON=xxxx01xx), versus
    POSCNT=MAXCNT Reset mode (QEICON=xxxx10xx) made it jump to MAXCNT, even though I wasn't using a Index pulse.

    Thanks for helping me sort this out.
    Mark

  9. #9
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Re: QEI Hardware Quadrature Encoder Inputs PIC 18F4431

    ...ie: 2767 -> 5535 -> 0 or 2767 -> 0 -> 5535.

  10. #10
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: QEI Hardware Quadrature Encoder Inputs PIC 18F4431

    Hi Mark,
    Did you have the Index input floating?
    If so it might pick up noise from the adjacent lines causing the counter to roll over. Anyway, that's not the way you're supposed to have it configured for what you're doing - as you've discovered.

    Any chanse you were looking at the first four digits of the POSCNT register(s) and missed the fact that it DID roll over to 65535?
    2767 -> (6)5535 -> 0 or 2767 -> 0 -> (6)5535

    Anyway, I'm glad you're back up and running.

    /Henrik.

  11. #11
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Re: QEI Hardware Quadrature Encoder Inputs PIC 18F4431

    Duh! didn't even think about that. Forest for the trees....
    Thanks
    Mark.

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