void __attribute__((interrupt, no_auto_psv)) _T1Interrupt(void)
{
    IFS0bits.T1IF = 0;   // Clear timer 1 interrupt flag
//    LEDRED = 1;
    CalcPid(&mypid);
//    LEDRED = 0;
}
int main() {

    unsigned char Lcd_LINE1[6] = {'\0'};
    unsigned char Lcd_LINE2[16] = {'\0'};
    unsigned int i;
    InitCan();
    InitQEI();
    InitPwm();
//    InitInt();
    InitAdc();
//    InitUart();
    
    //pid
    unsigned int *pwmOUT;
    pid_t mypid;
    float degPOT = 0.0;
    float degMTR = 0.0;


    while (1) {

        if(InData0[1] > 0){
//            if(InData0[2] == 1){
//                PDC2 = (unsigned int)(InData0[1]* 2 *.5914);
//                PDC1 = 0;
//            }
//            else{
//                PDC1 = (unsigned int)(InData0[1]* 2* .5914);
//                PDC2 = 0;
//            }
            pwmOUT = CalcPid(&mypid, degPOT, degMTR);
            PDC1 = *(pwmOUT + 0); // 16-bit register
            PDC2 = *(pwmOUT + 1); // 16-bit register
        }

        if (InData0[3] == 1) {
            C1TX0B4 = 2;
            C1TX0B1 = POSCNT;
            C1TX0B2 = C1RX0B2;
            C1TX0B3 = C1RX0B3;
            C1TX0CONbits.TXREQ = 1;
            while (C1TX0CONbits.TXREQ != 0);
        }
        msDelay(10);

    } //while
} // main