Qei module 18f4431

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
ccfred
Posts: 4
Joined: 05 Mar 2011 22:39
Location: Québec, Canada

Qei module 18f4431

#1 Post by ccfred » 17 Jun 2011 01:37

Hi everybudy,
I working pic18f4431 with a omron encoder 600p/r two phase with 4 edges read
I made a program from the interrupt routine an reach 50khz reading. Not bad, but not enough.
I have read in the spec there is a QEI MODULE can do it faster.
I look for a example of the minimun configuration to read possition an speed

I find the GS002.pdf from Microchip
void InitQEI(void)
{
ADPCFG |= 0x0038; // Configure QEI pins as digital inputs
QEICONbits.QEIM = 0; // Disable QEI Module
QEICONbits.CNTERR = 0; // Clear any count errors
QEICONbits.QEISIDL = 0; // Continue operation during sleep
QEICONbits.SWPAB = 0; // QEA and QEB not swapped
QEICONbits.PCDOUT = 0; // Normal I/O pin operation
QEICONbits.POSRES = 1; // Index pulse resets position counter
DFLTCONbits.CEID = 1; // Count error interrupts disabled
DFLTCONbits.QEOUT = 1; // Digital filters output enabled for QEn pins
DFLTCONbits.QECK = 5; // 1:64 clock divide for digital filter for QEn
DFLTCONbits.INDOUT = 1; // Digital filter output enabled for Index pin
DFLTCONbits.INDCK = 5; // 1:64 clock divide for digital filter for Index
POSCNT = 0; // Reset position counter
QEICONbits.QEIM = 6; // X4 mode with position counter reset by Index
return;
}

I'll that but the compiler dont accept all line.

Help me please

Thanks
ccfred

ccfred
Posts: 4
Joined: 05 Mar 2011 22:39
Location: Québec, Canada

Re: Qei module 18f4431

#2 Post by ccfred » 23 Jun 2011 03:05

Ok everyone I find out by myself
Here is the minimun setting for use an encoder with the QEI module
Voici ce que j'ai fait pour faire compter les tours de mon encoder Omron 2000ppr brancher sur le QEI Module de mon pic18f4431

ANSEL0 =0; // DÉACTIVE ENTRÉES ANALOGUE desable analog
ANSEL1 =0; // DÉACTIVE ENTRÉES ANALOGUE desable analog
PORTA = 0; // RESET PORTA
TRISA =0X3F; // ACTIVE LES 6 ENTRÉES PORTA set on porta 0to5
CAP1CON = 0; // desable
CAP2CON = 0; // desable
CAP3CON = 0; // desable
QEICON = 0b10011010; // 4x w/o index 2x w index qeicon = 0b10000100;
MAXCNTH = 0x1f; // -1+(2000*4)=7999=0x1f3f
MAXCNTL = 0x3f; // -1+(2000*2)=3999=0x0f9f
IPEN_BIT=0; // IPEN: Interrupt Priority Enable bit
// 1 = Enable priority levels on interrupts
IC2QEIE_BIT=1; // IC2 Interrupt Flag/QEI Interrupt Flag Enable bit
// 1 = IC2 interrupt enabled)
PEIE_BIT=1; // Peripheral Interrupt Enable bit
// 1 = Enables all unmasked peripheral interrupts
GIE_BIT=1; // Global Interrupt Enable bit
// 1 = Enables all unmasked interrupts
PORTB=0X00; // reset PORTB FOR LCD. DEFINE UP

PORTC =0X00; // RESET PORTC
TRISC =0X00; // ACTIVE LES 8 ENTRÉES PORTC activate output

PORTD=0X00; // RESET PORTD
TRISD=0X00; // ACTIVE LES 8 ENTRÉES PORTD activate output

int poss = 0;
long turncnt = 0; // total count in
POSCNTH = 0; // actual position count high 8 bits
POSCNTL = 0; // actual position count low 8 bits
void main(){
your code here
votre code ici

}

static void interrupt(){
if(IC2QEIF_BIT=1){
if (POSCNTH == 0){turncnt++;} //if carry over maxcount add 1 trurncnt
else {turncnt--;} //if borrow under maxcount sub 1 trurncnt
}
IC2QEIF_BIT = 0; // reset QEI maxcount or QEI index flag interrupt
}

Post Reply

Return to “mikroC PRO for PIC General”