Skip to main content
Visitor II
December 24, 2024
Question

Dead Time between different channels

  • December 24, 2024
  • 1 reply
  • 645 views

I want to configure dead time between different channels but I get the output as in the picture.Below is the PWM function I created for the BLDC motor and algorithm for each phase of BLDC motor. What could be the problem?BLDC_logic.png

PWM.jpg

 

 

void BLDC_SetPhase(uint8_t phase)
{
 switch (phase)
 {
 case 0: // AH = 1, AL = 0, BH = 0, BL = 1, CH = KAPALI, CL = KAPALI
 	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
 	__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 50);
 	HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_1);

 	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
 	HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);
 	__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 50);

 	HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_3);
 	HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_3);



 	break;
 case 1: // AH = 1, AL = 0, BH = KAPALI, BL = KAPALI, CH = 0, CL = 1
 	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
 	__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 50);
 	HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_1);

 	HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_2);
 	HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_2);

 	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);
 	HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_3);
 	__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 50);


 break;
 case 2: // AH = KAPALI, AL = KAPALI, BH = 1, BL = 0, CH = 0, CL = 1
 	HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_1);
 	HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_1);

 	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
 	__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 50);
 	HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_2);

 	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);
 	HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_3);
 	__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 50);


 break;
 case 3: // AH = 0, AL = 1, BH = 1, BL = 0, CH = KAPALI, CL = KAPALI
 	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
 	__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 50);
 	HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_2);

 	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
 	HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
 	__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 50);

 	HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_3);
 	HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_3);


 break;
 case 4: // AH = 0, AL = 1, BH = KAPALI, BL = KAPALI, CH = 1, CL = 0
 	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);
 	__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 50);
 	HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_3);

 	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
 	HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
 	__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 50);

 	HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_2);
 	HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_2);


 break;
 case 5: // AH = KAPALI, AL = KAPALI, BH = 0, BL = 1, CH = 1, CL = 0
 	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);
 	__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 50);
 	HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_3);

 	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
 	HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);
 	__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 50);

 	HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_1);
 	HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_1);


 break;
 default:
 break;
 }
}

 

 

 

1 reply

TDK
Super User
December 24, 2024

Dead time is configured in the BDTR register. Doesn't look like you're configuring that anywhere in the posted code. Typically it would be done when initializing the timer.

With HAL, this is done with the HAL_TIMEx_ConfigBreakDeadTime function.

"If you feel a post has answered your question, please click ""Accept as Solution""."