//=== Comparator 2 Settings ================/// comparator 2 reverse input channel selection # defineCMP2_C2NCH (x) CM2CON1 = (CM2CON1 & 0xFC) | x # defineCMP2_IE_ENBC2IE = 1 # defineCMP2_IE_DISC2IE = 0 # Leading = 1 // positive edge interruption flag is allowed # defineCMP2_INTP_DISC2INTP = 0 // positive edge interruption flag is not allowed # Leading = 1/ /negative edge interruption flag can be generated # defineCMP2_INTN_DISC2INTN = 0 // negative edge interruption flag cannot be generated # defineCMP2_OUT C2OUT // comparator 2 output bit //********* * ************************** // Function Name: init_Cmp1BC // function: Initialize the comparator 1 settings // entry parameters: // exit parameters: none ////*********************************** * *** void Init_Cmp2BC (void) {CM2CON0 = 0X84 | (1 <4); // enable comparator fast mode comparator output polarity inversion // C2HYS = 1; // comparator lagging CM2CON1 = 0X00; // C2OE = 1; // output enabling // C2INTP = 1; // allow forward edge // C2INTN = 1; // allow negative edge }//******************************** * *** // Function Name: setCmpParam // function: Set the comparator parameter // entry parameter: The current step 1-6 // exit parameter: // blood: this setting is set to BLDC no-sense detection back-EMR //***************************** * ********* void SetCmpParam (uint8 Invalue) {if (F_Direction = ZEN) {switch (Invalue) // take the step to go to {case 1: // AB CMP2_C2NCH (CPLC_CHANAL); // detect the cpoint potential CMP2_INTP_DIS; CMP2_INTN_ENB; // detect the descent edge break; case 2: // ACCMP2_C2NCH (CPLB_CHANAL); // detect the potential of point B CMP2_INTN_DIS; CMP2_INTP_ENB; // detect the descending edge break; case 3: // reset (CPLA_CHANAL); // detect a-point potential CMP2_INTP_DIS; then; // detect a-point potential along break; case 4: // BACMP2_C2NCH (CPLC_CHANAL); // detect a-point potential CMP2_INTN_DIS; break; // check the descending break; case 5: // CACMP2_C2NCH (CPLB_CHANAL); // check the potential of point B CMP2_INTP_DIS; CMP2_INTN_ENB; // check the descending break; case 6: // CBCMP2_C2NCH (CPLA_CHANAL); // detects the-Point potential CMP2_INTN_DIS; CMP2_INTP_ENB; // detects the top-down break; default: return; // If the hall signal is incorrect, exit // break;} else // reverse {switch (Invalue) // take a step to reverse {case 1: // AB CMP2_C2NCH (CPLC_CHANAL ); // detect the cpoint potential CMP2_INTN_DIS; CMP2_INTP_ENB; // detect the descending break; case 2: // ACCMP2_C2NCH (CPLB_CHANAL); // detect the cpoint potential CMP2_INTP_DIS; done; // check the descent edge break; case 3: // BCCMP2_C2NCH (CPLA_CHANAL); // check the cpoint potential CMP2_INTN_DIS; CMP2_INTP_ENB; // check the descending edge break; case 4: // BACMP2_C2NCH (CPLC_CHANAL); // detects the cpoint potential CMP2_INTP_DIS; break; // detects the descent edge break; case 5: // Digest (CPLB_CHANAL); // detects the cpoint potential CMP2_INTN_DIS; CMP2_INTP_ENB; // check the descending break; case 6: // listen (CPLA_CHANAL); // check the cpoint potential CMP2_INTP_DIS; CMP2_INTN_ENB; // check the descending edge break; default: return; // If the hall signal is incorrect, exit // break; }}// --- application instance ---- // CMP2 to initialize Init_Cmp2BC (); // initialize the comparator 2 // set the comparator parameter SetCmpParam (1 );//