赞
踩
时钟配置
互补输出
开启中断
计数10000次自动重载
开启中断
tim1初始时设置捕获值和是否开启通道应视情况
/* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM1_Init(); MX_TIM2_Init(); /* USER CODE BEGIN 2 */ __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_1); // HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_1); { __HAL_TIM_ENABLE(&htim1); __HAL_TIM_MOE_ENABLE(&htim1); } // HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_1); { __HAL_TIM_ENABLE_IT(&htim1, TIM_FLAG_UPDATE); } HAL_TIM_Base_Start(&htim2); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */
/** * @brief This function handles System tick timer. */ void SysTick_Handler(void) { /* USER CODE BEGIN SysTick_IRQn 0 */ /* USER CODE END SysTick_IRQn 0 */ HAL_IncTick(); /* USER CODE BEGIN SysTick_IRQn 1 */ if (uwTick % 10000) { uint32_t cnt = __HAL_TIM_GetCounter(&htim2); } /* USER CODE END SysTick_IRQn 1 */ } /** * @brief This function handles TIM1 update interrupt. */ void TIM1_UP_IRQHandler(void) { /* USER CODE BEGIN TIM1_UP_IRQn 0 */ if (__HAL_TIM_GET_FLAG(&htim1, TIM_FLAG_UPDATE)) { } /* USER CODE END TIM1_UP_IRQn 0 */ HAL_TIM_IRQHandler(&htim1); /* USER CODE BEGIN TIM1_UP_IRQn 1 */ /* USER CODE END TIM1_UP_IRQn 1 */ }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。