PWM组合3相模式,ADC触发问题
用通道6 PWM互补模式,后来增加了通道5无输出,中断触发。中断回调函数TIM1_TRG_COM_TIM17_IRQRST没有进入中断,进入中断会有个LED闪烁。int main(void){HAL_Init();SystemClock_Config(); /* Compute the value of ARR register to generate signal frequency at 10 Khz */mcuFreq = HAL_RCC_GetSysClockFreq();timerPeriod = (uint32_t)((mcuFreq / 10000) - 1); MX_GPIO_Init();MX_TIM1_Init();MX_ADC1_Init();MX_USART1_UART_Init();/* USER CODE BEGIN 2 */__HAL_UART_FLUSH_DRREGISTER(&huart1); __HAL_TIM_ENABLE_IT(&htim1,TIM_IT_UPDATE | TIM_IT_TRIGGER); valBuf = setDutyAsPercentage(20);valBuf = setDutyAsPercentage(50);valBuf = setDutyAsPercentage(80);if(HAL_TIMEx_GroupChannel5(&htim1, (TIM_GROUPCH5_OC1REFC |\ TIM_GROUPCH5_OC2REFC |\ TIM_GROUPCH5_OC3REFC)) != HAL_OK) Error_Handler(); if(HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_1) != HAL_OK) Error_Handler();if(HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_1) != HAL_OK) Error_Handler();if(HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_2) != HAL_OK) Error_Handler();if(HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_2) != HAL_OK) Error_Handler();if(HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_3) != HAL_OK) Error_Handler();if(HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_3) != HAL_OK) Error_Handler();if(HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_5) != HAL_OK) Error_Handler(); //ADC Trigger TIM1->CCR1 = valBuf;TIM1->CCR2 = valBuf;TIM1->CCR3 = valBuf; HAL_UART_Receive_IT(&huart1, uartRxBuf, 1); //if(HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED) != HAL_OK); Error_Handler(); //HAL_ADCEx_InjectedStart_IT(&hadc1); while (1){ }}// ---------------------------------------- stm32g4xx_it.c ----------------------------------------//void TIM1_TRG_COM_TIM17_IRQHandler(void){ HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5); testCounter++; HAL_TIM_IRQHandler(&htim1);}
页:
[1]