Needed to build a tester for some high resolution QEI encoders. The speed and number of counts per revolution favored a hardware motor control solution for the A/B/Index signals vs a software solution. I had a PIC32MK GP board but needed the MC chip on the board so first the first step was to swap controllers on the board without destroying it.
https://www.allaboutcircuits.com/ne...-a-new-microcontroller-family-from-microchip/

Used a hot air gun to remove the GP and install the MC. Used polyimide tape to protect other components
from the heat.
Modded dev MC board with TTL 7433N (from the junk box) level converter in mikro bus socket for the encoder signals.
https://www.celeramotion.com/sites/default/files/LP-Data_Sheet-Packaged_DRC-M35.pdf
The test software just updates a few leds, and outputs the qei position count register to uart #3.
https://github.com/nsaspook/m35_pic32mk_mc
The QEI device easily tracks the >320,000 counts per turn of the encoder knob with only a few config values in module SFR registers.
http://ww1.microchip.com/downloads/en/DeviceDoc/60001346A.pdf
https://www.allaboutcircuits.com/ne...-a-new-microcontroller-family-from-microchip/


Used a hot air gun to remove the GP and install the MC. Used polyimide tape to protect other components
from the heat.

Modded dev MC board with TTL 7433N (from the junk box) level converter in mikro bus socket for the encoder signals.
https://www.celeramotion.com/sites/default/files/LP-Data_Sheet-Packaged_DRC-M35.pdf
The test software just updates a few leds, and outputs the qei position count register to uart #3.
C:
// *****************************************************************************
// *****************************************************************************
// Section: Main Entry Point
// *****************************************************************************
// *****************************************************************************
/* redirect printf to uart3 */
void _mon_putc(char c)
{
while (DRV_USART0_TransmitBufferIsFull()) {
}; //Wait till transmission is complete
DRV_USART0_WriteByte(c);
}
int main(void)
{
int32_t itest, update_count = 0;
/* Initialize all MPLAB Harmony modules, including application(s). */
SYS_Initialize(NULL);
/* serial clock is off, this is actually 76.8 kb/s */
DRV_USART0_BaudSet(115200);
while (true) {
/* Maintain state machines of all polled MPLAB Harmony modules. */
SYS_Tasks();
/* update local value of the position counter */
itest = POS1CNT;
if (update_count++ > 20480) {
/* flash the board leds using the position counter bits */
LATGbits.LATG12 = itest >> 10;
LATGbits.LATG13 = itest >> 12;
LATGbits.LATG14 = itest >> 14;
/* send to uart3 the current POS1CNT value */
printf("count %8i\r\n", itest);
update_count = 0;
}
}
/* Execution should not come here during normal operation */
return( EXIT_FAILURE);
}
The QEI device easily tracks the >320,000 counts per turn of the encoder knob with only a few config values in module SFR registers.
C:
int32_t m35_init_qei(void)
{
/* port pin numbers from port_p32mk1024mcf100.h */
QEA1R = 0x00;
QEB1R = 0x0D;
INDX1R = 0x00;
HOME1R = 0x04;
QEI1CON = 0;
QEI1IOC = 0;
QEI1IOCbits.QEAPOL = 1;
QEI1IOCbits.QEBPOL = 1;
QEI1IOCbits.IDXPOL = 1;
QEI1IOCbits.SWPAB = 1;
QEI1CONbits.PIMOD = 0;
QEI1CONbits.QEIEN = 1;
POS1CNT = 0;
return 0;
}