|
|
View previous topic :: View next topic |
Author |
Message |
aaaaamartin
Joined: 17 Apr 2005 Posts: 39 Location: Germany Stuttgart
|
Help with QEI |
Posted: Tue Oct 11, 2005 11:11 am |
|
|
Hello,
I want to use the built in QEI on a 18F4431 with a quad encoder.
No its not the one you mount to the motorshaft, its one for manual data entry. However this is much slower, i think why not use the QEI for that as wel.
The problem is, I can not figur out why the interrupts happen more than once. And this is also different right after direction changes and whether I rotate cw or ccw.
Is this normal behaviour ?
Heres is some code if one has an encoder to try out.
Code: |
#ZERO_RAM
#include <18F4431.h>
#fuses NOWDT, H4, NOPUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, SSP_RC
#use delay(clock=40000000)
#use rs232 (baud=38400, xmit=PIN_C6, rcv=PIN_C7, disable_ints)
#BYTE QEICON=0xFB6 // quadrature configure
#bit QEICONDIR=0xFB6.5
#BYTE DFLTCON=0xF60 // quadrature noise filter configure
#BYTE CAP2BUFL=0xF66 // position counter
#BYTE CAP2BUFH=0xF67
#BYTE CAP3BUFL=0xF64 //max count
#BYTE CAP3BUFH=0xF65
int drcnt;
int qeicnt;
#int_IC3DR
void ic3dr_interrupt (void) {
output_toggle (PIN_D0);
drcnt ++;
}
#int_IC2QEI
void ic2qei_interrupt (void) {
output_toggle (PIN_D1);
qeicnt++;
}
void main (void) {
enable_interrupts (INT_IC2QEI); // interrupt on maxcount or underflow
enable_interrupts (INT_IC3DR);
enable_interrupts (GLOBAL);
QEICON=0b00011000; // quad in x4 mode, resettable by maxcount
DFLTCON=49; // noise filter on QEA, QEB,, 1:2 clock
CAP3BUFL=0x0F; // set max count
CAP3BUFH=0x00;
CAP2BUFL=0x00; // reset count
CAP2BUFH=0x00;
while (1) {
printf("\rCAP2:%X-%X ; CAP3:%X-%X ; QEICON:%X ;qeicnt %03u ; drcnt: %03u", CAP2BUFH, CAP2BUFL, CAP3BUFH, CAP3BUFL, QEICON, qeicnt, drcnt);
delay_ms (50);
}
}
|
Thanks you, Martin |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
$0.02 hardware hypothesis |
Posted: Tue Oct 11, 2005 5:20 pm |
|
|
Are you using a mechanical encoder or an optical one?
Mechanical encoders have the bouncing problem, because they have mechanical switches. If you want to connect a mechanical encoder to the interupt, you need to debounce all of its outputs. There is a sample circuit at the bottom of page 1 of this datasheet: http://www.bourns.com/pdf/ecw1j.pdf
Optical encoders don't have this problem. |
|
|
aaaaamartin
Joined: 17 Apr 2005 Posts: 39 Location: Germany Stuttgart
|
|
Posted: Wed Oct 12, 2005 3:51 am |
|
|
It's a mechanical encoder by ALPS.
I dont't think it's a debounce problem.
It's working in both directions, and in all cases counts one time,
except I change direction from cw to ccw, then it counts -3 right after the change. Then it coutns -1 again, as it should.
Martin |
|
|
sseidman
Joined: 14 Mar 2005 Posts: 159
|
|
Posted: Wed Oct 12, 2005 8:29 am |
|
|
aaaaamartin wrote: | It's a mechanical encoder by ALPS.
I dont't think it's a debounce problem.
It's working in both directions, and in all cases counts one time,
except I change direction from cw to ccw, then it counts -3 right after the change. Then it coutns -1 again, as it should.
Martin |
I'd still start by debouncing. The noise filters on the QEI might take care of all the problems, except during the direction change you describe.
Scott |
|
|
aaaaamartin
Joined: 17 Apr 2005 Posts: 39 Location: Germany Stuttgart
|
|
Posted: Wed Oct 12, 2005 8:54 am |
|
|
I'll do a software workarround.
If anyone else thinks this abnormal .....
Thanks
Martin |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|