View previous topic :: View next topic |
Author |
Message |
hasimi20
Joined: 04 Sep 2010 Posts: 19
|
qei 32bit |
Posted: Sat Aug 18, 2012 8:30 am |
|
|
Hi, I have made a working qei program using ccs 4.128 for my 500 pulse/rotation encoder and I am using QEI_MODE_X2_RESET_ON_MATCH. The problem is, the qei is limited to 16bit only, and my project needs 32bit. Is there any c program tips to increase the 16bit counting to 32bit encoder counting? Fyi, at this moment I am using if-else and make32(), but its always miss count. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Aug 18, 2012 3:22 pm |
|
|
Have you tried simply counting under/overflow of your 16bit variables?
Mike |
|
|
hasimi20
Joined: 04 Sep 2010 Posts: 19
|
|
Posted: Sun Aug 19, 2012 6:29 am |
|
|
counting under/overflow? dont understand, could you please explain?? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Aug 19, 2012 8:50 am |
|
|
This is taken from the PIC18F4431 data sheet.
Quote: | If the encoder is traveling in the forward direction,
POSCNT is reset (00h) on the next clock
edge when POSCNT = MAXCNT. An interrupt
event is triggered on the next TCY after the Reset
(see Figure 17-10)
If the encoder is traveling in the reverse
direction and the value of POSCNT reaches
00h, POSCNT is loaded with the contents of the
MAXCNT register on the next clock edge. An
interrupt event is triggered on the next TCY after
the load operation (see Figure 17-10). |
The qei variable POSCNT is the 16 LSBs of your 32bits.
When encoder is traveling forwards, an interrupt is generated as POSCNT overflows past MAXCNT. When travelling in reverse, the interrupt happens as POSCNT underflows through zero. I'm suggesting you could use the interrupts to increase/decrease a 16MSB_COUNTER. If you make MAXCNT = 0xFFFF then you should have a 32 bit system.
Mike |
|
|
|