void Commutation(unsigned int step,unsigned int OutPwmValue,unsigned int PWM_ON_flag){//if(PWM_ON_flag==0) //Turn off output if not started{CW_ATIM->CH1CCRA=0;CW_ATIM->CH2CCRA=0;CW_ATIM->CH3CCRA=0;//Timer output comparison is set to 0ATIM_CtrlPWMOutputs(DISABLE);PWM_AL_OFF; PWM_BL_OFF; PWM_CL_OFF;return;}PWM_AL_OFF; PWM_BL_OFF; PWM_CL_OFF;//Output PWM to the upper bridge, example: AB means (A upper bridge is on, B lower bridge is on)if(step==0||step==1){CW_ATIM->CH1CCRA=OutPwmValue; CW_ATIM->CH2CCRA=0; CW_ATIM->CH3CCRA=0; } //0:AB; 1:ACif(step==2||step==3){CW_ATIM->CH1CCRA=0; CW_ATIM->CH2CCRA=OutPwmValue; CW_ATIM->CH3CCRA=0; } //2:BC; 3:BAif(step==4||step==5){CW_ATIM->CH1CCRA=0; CW_ATIM->CH2CCRA=0; CW_ATIM->CH3CCRA=OutPwmValue;} //4:CA; 5:CB//Control IO lower bridgeif(step==0||step==5){PWM_AL_OFF; PWM_CL_OFF;PWM_BL_ON;} //AB CB; B lower bridge is turned onelse if(step==1||step==2){ PWM_AL_OFF; PWM_BL_OFF; PWM_CL_ON;}//AC BC; C lower bridge is onelse if(step==3||step==4){ PWM_BL_OFF; PWM_CL_OFF; PWM_AL_ON;}//BA CA; A lower bridge is onATIM_CtrlPWMOutputs(ENABLE); //The output is valid}
void GTIM2_IRQHandler(void){unsigned int x;/* USER CODE BEGIN */if (GTIM_GetITStatus(CW_GTIM2, GTIM_IT_CC1)){GTIM_ClearITPendingBit(CW_GTIM2, GTIM_IT_CC1);}if (GTIM_GetITStatus(CW_GTIM2, GTIM_IT_CC2)){GTIM_ClearITPendingBit(CW_GTIM2, GTIM_IT_CC2);}if (GTIM_GetITStatus(CW_GTIM2, GTIM_IT_CC3)){GTIM_ClearITPendingBit(CW_GTIM2, GTIM_IT_CC3);}HALLcount++; //Hall pulse countx=HALL_Check(); //According to the Hall count value, the statusCur_step=STEP_TAB[x-1]; //Get the commutation sequence bitif(Motor_Start_F==1&&ErrorCode==0) //Change phase according to start and stop statusCommutation(Cur_step,OutPwm,Motor_Start_F);/* USER CODE END */}
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet