void BLDCMotorPrepareCommutation(u8 pos, TIMOCMODE_Typedef TIM_CHxMode, TIMOCMODE_Typedef TIM_CHxNMode)
{
if (pos == 0){
/* Channel1 configuration: CH1 output: PWM */
TIM_SelectOCxM (TIM1, TIM_Channel_1, TIM_CHxMode);
TIM_CCxCmd (TIM1, TIM_Channel_1, TIM_CCx_Enable);
TIM_CCxNCmd (TIM1, TIM_Channel_1, TIM_CCxN_Disable);
/* Channel2 configuration: CH2N output: PWM */
TIM_SelectOCxM (TIM1, TIM_Channel_2, TIM_CHxNMode);
TIM_CCxCmd (TIM1, TIM_Channel_2, TIM_CCx_Disable);
TIM_CCxNCmd (TIM1, TIM_Channel_2, TIM_CCxN_Enable);
/* Channel3 configuration: CH3 None */
TIM_CCxCmd (TIM1, TIM_Channel_3, TIM_CCx_Disable);
TIM_CCxNCmd (TIM1, TIM_Channel_3, TIM_CCxN_Disable);
}
else if (pos == 1){
/* Channel1 configuration: CH1 output: PWM */
TIM_SelectOCxM (TIM1, TIM_Channel_1, TIM_CHxMode);
TIM_CCxCmd (TIM1, TIM_Channel_1, TIM_CCx_Enable);
TIM_CCxNCmd (TIM1, TIM_Channel_1, TIM_CCxN_Disable);
/* Channel2 configuration: CH2 None */
TIM_CCxCmd (TIM1, TIM_Channel_2, TIM_CCx_Disable);
TIM_CCxNCmd (TIM1, TIM_Channel_2, TIM_CCxN_Disable);
/* Channel3 configuration: CH3N output: PWM */
TIM_SelectOCxM (TIM1, TIM_Channel_3, TIM_CHxNMode);
TIM_CCxCmd (TIM1, TIM_Channel_3, TIM_CCx_Disable);
TIM_CCxNCmd (TIM1, TIM_Channel_3, TIM_CCxN_Enable);
}
else if (pos == 3){
/* Channel1 configuration: CH1 None */
TIM_CCxCmd (TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd (TIM1, TIM_Channel_1, TIM_CCxN_Disable);
/* Channel2 configuration: CH2 output: PWM */
TIM_SelectOCxM (TIM1, TIM_Channel_2, TIM_CHxMode);
TIM_CCxCmd (TIM1, TIM_Channel_2, TIM_CCx_Enable);
TIM_CCxNCmd (TIM1, TIM_Channel_2, TIM_CCxN_Disable);
/* Channel3 configuration: CH3N output: PWM */
TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_CHxNMode);
TIM_CCxCmd (TIM1, TIM_Channel_3, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);
}
else if (pos == 7){
/* Channel1 configuration: CH1N output: PWM */
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_CHxNMode);
TIM_CCxCmd (TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
/* Channel2 configuration: CH2 output: PWM */
TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_CHxMode);
TIM_CCxCmd (TIM1, TIM_Channel_2, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
/* Channel3 configuration: CH3 None */
TIM_CCxCmd (TIM1, TIM_Channel_3, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
}
else if (pos == 6){
/* Channel1 configuration: CH1N output: PWM */
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_CHxNMode);
TIM_CCxCmd (TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
/* Channel2 configuration: CH2 None */
TIM_CCxCmd (TIM1, TIM_Channel_2, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
/* Channel3 configuration: CH3 output: PWM */
TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_CHxMode);
TIM_CCxCmd (TIM1, TIM_Channel_3, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
}
else if (pos == 4){
/* Channel1 configuration: CH1 None */
TIM_CCxCmd (TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
/* Channel2 configuration: CH2N output: PWM */
TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_CHxNMode);
TIM_CCxCmd (TIM1, TIM_Channel_2, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);
/* Channel3 configuration: CH3 output: PWM */
TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_CHxMode);
TIM_CCxCmd (TIM1, TIM_Channel_3, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
}
}