I am trying to run a BLDC motor with TIM1 on STM32F401RE. I want to use a software commutation event with HAL drivers as is done in the "6step" examples. So far the call back is not working. Please tell me what I am missing. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-03 12:01 AM
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
//TimHandle.Instance = TIM1;
HAL_TIMEx_ConfigCommutEvent_IT(&htim1, TIM_TS_NONE, TIM_COMMUTATION_SOFTWARE);
/* USER CODE END Init */
/////////////////////////////////////////////////////////////////////////////////////////
/* USER CODE BEGIN 4 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim){
if(htim->Instance == (TIM2)){
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_14);
HAL_TIM_GenerateEvent(&htim1, TIM_EventSource_COM);
//count++;
//BRG_switch(); //<-this call is working
}
//if(htim->Instance == (TIM1)){pwm++;}
}
void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim1){
count++;
BRG_switch(); //<-this call is not working!
}
Solved! Go to Solution.
- Labels:
-
STM32 Motor Control
-
STM32F4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-03 5:21 AM
YEP, sorry, I found the answer. The
HAL_TIMEx_ConfigCommutEvent_IT(&htim1, TIM_TS_NONE, TIM_COMMUTATION_SOFTWARE);
HAS TO BE AFTER MX_TIM1_Init();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_TIM1_Init();
MX_ADC1_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
//TimHandle.Instance = TIM1;
HAL_TIM_Base_Start_IT(&htim2);
HAL_TIM_Base_Start_IT(&htim1);
HAL_TIM_Base_MspInit(&TimHandle);
HAL_TIMEx_ConfigCommutEvent_IT(&htim1, TIM_TS_NONE, TIM_COMMUTATION_SOFTWARE);
// TIM1->DIER|=TIM_DIER_UIE;
//TIM1->DIER|=TIM_DIER_COMIE;
//__HAL_TIM_ENABLE_IT(&htim1, TIM_IT_COM);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-03 5:21 AM
YEP, sorry, I found the answer. The
HAL_TIMEx_ConfigCommutEvent_IT(&htim1, TIM_TS_NONE, TIM_COMMUTATION_SOFTWARE);
HAS TO BE AFTER MX_TIM1_Init();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_TIM1_Init();
MX_ADC1_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
//TimHandle.Instance = TIM1;
HAL_TIM_Base_Start_IT(&htim2);
HAL_TIM_Base_Start_IT(&htim1);
HAL_TIM_Base_MspInit(&TimHandle);
HAL_TIMEx_ConfigCommutEvent_IT(&htim1, TIM_TS_NONE, TIM_COMMUTATION_SOFTWARE);
// TIM1->DIER|=TIM_DIER_UIE;
//TIM1->DIER|=TIM_DIER_COMIE;
//__HAL_TIM_ENABLE_IT(&htim1, TIM_IT_COM);
