/* setup timer2 with 2usec period */
T2CONbits.T32 = 0; // timer2: disable 32-bit timer mode
T2CONbits.TCKPS = 0; // timer2: prescale 1:1
T2CONbits.TCS = 0; // timer2: asynch
T2CONbits.TGATE = 0; // timer2: non-gated
PR2 = 40; // timer2: 40MHz / 40 = 1MHz toggle freq (500kHz signal)
T2CONbits.TON = 1; // timer2: turn on