Dear Matt
The code is shown below
This function first initialises the qei with all the registers set to their default values and then modifies the registers for my application. Here i have configured the QEI interrupt for compare position 0. And the compare position 0 register is preloaded to 1. so i get an interrupt for every "absolute forward" motion tick. That might not be necessary for your application.
The register LPC_QEI->QEIPOS holds the current position value. It is a read only register. So an instruction like
variable = LPC_QEI->QEIPOS; would load the current value in the variable.
I have not tried this myself (not neede for my application) but am sure that it will work.
The default clock for all peripherals is CCLK/4. So though the core operates at 96MHz, the peripherals will operate at 24MHz. so an instruction is used to make the QEI peripheral clock equal to core clock.
The QEI is used in x4 mode so that i get a pulse (internal) for every rising as well as falling edges of both the phase a and b. So you have an encoder of say 2500 ppr,effectively you will get 10000 ppr in the QEI position register.
void init_qei(void) {
LPC_SC->PCONP &= 0xFFFBFFFF;
LPC_SC->PCONP |= 0x00040000; // power up the QEI peripheral
/* reset alll the QEI registers to their default (reset) values */
LPC_QEI->QEICON = 0;
LPC_QEI->QEICONF = 0;
LPC_QEI->QEIMAXPOS = 0;
LPC_QEI->CMPOS0 = 0;
LPC_QEI->CMPOS1 = 0;
LPC_QEI->CMPOS2 = 0;
LPC_QEI->INXCMP = 0;
LPC_QEI->QEILOAD = 0;
LPC_QEI->VELCOMP = 0;
LPC_QEI->FILTER = 0;
LPC_QEI->QEICLR = 0xFFFFFFFF;
LPC_QEI->QEIIEC = 0xFFFFFFFF;
LPC_QEI->QEIIES = 0;
/* configure the qei for my application*/
LPC_SC->PCLKSEL1 &= 0xFFFFFFFE;
LPC_SC->PCLKSEL1 |= 1; // QEI clock selection
// QEI clock = core clock = 96MHz
LPC_PINCON->PINSEL3 &= 0xFFFF3CFF;
LPC_PINCON->PINSEL3 |= 0x00004100; // set pha and phb as inputs
LPC_PINCON->PINMODE3 &= 0xFFFF3CFF;
LPC_PINCON->PINMODE3 |= 0; // set pha and phb to pull up mode
LPC_QEI->QEICONF &= 0xFFFFFFF9;
LPC_QEI->QEICONF |= 4; // select sigmode and x4 mode
LPC_QEI->QEIMAXPOS = 0xFFFFFFFF; // set the max encoder position
LPC_QEI->CMPOS0 = 1; // set compare position 0 value
LPC_QEI->QEIIES = 0x00000040; // enable position 0 compare interrupt
}
hope this helps
Rahul
Hi,
I want to write an isr routine at the vector location 0x000BC (QEI interrupt).(LPC 1768)
Please let me know how do i put my isr in the above vector location so that when the hardware interrupt occurs i can perform my specified task.
Regards,
Dhaval