// Quadrature Encoder Truth Table // 전제조건: A상이 B상보다 90도 앞서는 것이 전진(CW,증가)이다. // ------+------------------------------------------------- // (A:B) | Curr. // Prev. | (0:0) (0:1) (1:0) (1:1) // ------+------------------------------------------------- // (0:0) | No_Change Backward Forward Error // (0:1) | Forward No_Change Error Backward // (1:0) | Backward Error No_Change Forward // (1:1) | Error Forward Backward No_Change // ------+-------------------------------------------------- // 홀센서 각도 계산 // 2 N 극 자석 => (N = Total_Number) // 홀센서가 한 측정 가능한 폭 중 하이구간의 Percent // 360/N * (Proportion ± 0.5 * Percent) // 24극 자석 (N = 12) void __ISR(_INPUT_CAPTURE_1_VECTOR, ipl5) IC1_Interrupt_ISR(void) { mIC1ClearIntFlag(); if ((bPrevEncLeftPhaseA == bPrevEncLeftPhaseB) && (IN_ENC_LEFT_A != IN_ENC_LEFT_B)) { if (bPrevEncLeftPhaseA == IN_ENC_LEFT_A) u16EncoderLeft++; else u16EncoderLeft--; } else if ((bPrevEncLeftPhaseA != bPrevEncLeftPhaseB) && (IN_ENC_LEFT_A == IN_ENC_LEFT_B)) { if (bPrevEncLeftPhaseA == IN_ENC_LEFT_A) u16EncoderLeft--; else u16EncoderLeft++; } // update previous phase bPrevEncLeftPhaseA = IN_ENC_LEFT_A; bPrevEncLeftPhaseB = IN_ENC_LEFT_B; } void __ISR(_INPUT_CAPTURE_2_VECTOR, ipl5) IC2_Interrupt_ISR(void) { mIC2ClearIntFlag(); if ((bPrevEncLeftPhaseA == bPrevEncLeftPhaseB) && (IN_ENC_LEFT_A != IN_ENC_LEFT_B)) { if (bPrevEncLeftPhaseA == IN_ENC_LEFT_A) u16EncoderLeft++; else u16EncoderLeft--; } else if ((bPrevEncLeftPhaseA != bPrevEncLeftPhaseB) && (IN_ENC_LEFT_A == IN_ENC_LEFT_B)) { if (bPrevEncLeftPhaseA == IN_ENC_LEFT_A) u16EncoderLeft--; else u16EncoderLeft++; } // update previous phase bPrevEncLeftPhaseA = IN_ENC_LEFT_A; bPrevEncLeftPhaseB = IN_ENC_LEFT_B; } void __ISR(_INPUT_CAPTURE_3_VECTOR, ipl5) IC3_Interrupt_ISR(void) { mIC3ClearIntFlag(); if ((bPrevEncRightPhaseA == bPrevEncRightPhaseB) && (IN_ENC_RIGHT_A != IN_ENC_RIGHT_B)) { if (bPrevEncRightPhaseA == IN_ENC_RIGHT_A) u16EncoderRight--; else u16EncoderRight++; } else if ((bPrevEncRightPhaseA != bPrevEncRightPhaseB) && (IN_ENC_RIGHT_A == IN_ENC_RIGHT_B)) { if (bPrevEncRightPhaseA == IN_ENC_RIGHT_A) u16EncoderRight++; else u16EncoderRight--; } // update previous phase bPrevEncRightPhaseA = IN_ENC_RIGHT_A; bPrevEncRightPhaseB = IN_ENC_RIGHT_B; } void __ISR(_INPUT_CAPTURE_4_VECTOR, ipl5) IC4_Interrupt_ISR(void) { mIC4ClearIntFlag(); if ((bPrevEncRightPhaseA == bPrevEncRightPhaseB) && (IN_ENC_RIGHT_A != IN_ENC_RIGHT_B)) { if (bPrevEncRightPhaseA == IN_ENC_RIGHT_A) u16EncoderRight--; else u16EncoderRight++; } else if ((bPrevEncRightPhaseA != bPrevEncRightPhaseB) && (IN_ENC_RIGHT_A == IN_ENC_RIGHT_B)) { if (bPrevEncRightPhaseA == IN_ENC_RIGHT_A) u16EncoderRight++; else u16EncoderRight--; } // update previous phase bPrevEncRightPhaseA = IN_ENC_RIGHT_A; bPrevEncRightPhaseB = IN_ENC_RIGHT_B; }