Hi Mark,
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'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.
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.I can change MAXCNT, but that doesn't put it in the middle of the count range and avoid the rollover.
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.
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.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.
If all you want is a 16 bit counter, starting in the "middle" then try this: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.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
/Henrik.




Bookmarks