brians | 0ab60bb | 2013-01-31 02:21:51 +0000 | [diff] [blame] | 1 | // Quad Encoder stuff
|
| 2 |
|
| 3 |
|
| 4 | // enable the quadrature encode peripheral and peripherial clock
|
| 5 |
|
| 6 | SC->PCONP |=0x00040000; // bit 18 of PCONP set to 1
|
| 7 | SC->PCLKSEL1 |=0x00000001; /* bits 1,0 00 CCLK/4
|
| 8 | 01 CCLK
|
| 9 | 10 CCLK/2
|
| 10 | 11 CCLK/8 */
|
| 11 |
|
| 12 |
|
| 13 | // Enable pins for QEI MCI0, MCI1 (PhA PhB, signals respectively)
|
| 14 |
|
| 15 |
|
| 16 | PINCON->PINSEL3 = ((PINSEL3 &=0xFFFF3DFF) |= 0x00004100); /* 01 in bits 9:8 and 15:14*/
|
| 17 | //PINCON->PINSEL3 = ((PINSEL3 &=0xFFFCFFFF) |= 0x00010000); /* Turns on MCI2 index input 17:16 = 01*/
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 | // Specify Quadriture phase mode
|
| 22 |
|
| 23 | // QEI->QEICON &= 0xFFFFFFFE; /* Clears position counter */
|
| 24 | QEI->QEICONF &= 0XFFFFFFFD; /* Sets bit 1 to 0, Signal mode to Quad Phase */
|
| 25 | // QEI->QEICON |= 0X00000002; /* Bit 2 to 1 counts both PhA and PhB for higher resolution */
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 | // QEI->FILTER = ****Whatever Sampling size we want*** /* Sets the number of consecutive pulses for a change in direction, etc to accepted */
|
| 30 |
|
| 31 |
|
| 32 | // Set Various Attributes
|
| 33 |
|
| 34 | // QEI->QEIMAXPOS = *****insert max position*****;
|
| 35 |
|
| 36 |
|
| 37 | /* Note: QEI->QEIPOS is a read only section that stores the current position */ |