标题: STM32F4 HAL_PWM测频程序 [打印本页]

作者: zlkj    时间: 2024-10-8 16:09
标题: STM32F4 HAL_PWM测频程序
  1. int main(void)
  2. {
  3.   /* USER CODE BEGIN 1 */
  4.         uint8_t i=1;
  5.   /* USER CODE END 1 */

  6.   /* MCU Configuration----------------------------------------------------------*/

  7.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  8.   HAL_Init();

  9.   /* USER CODE BEGIN Init */

  10.   /* USER CODE END Init */

  11.   /* Configure the system clock */
  12.   SystemClock_Config();

  13.   /* USER CODE BEGIN SysInit */

  14.   /* USER CODE END SysInit */

  15.   /* Initialize all configured peripherals */
  16.   MX_GPIO_Init();
  17.   MX_USART3_UART_Init();
  18.   MX_USB_OTG_FS_PCD_Init();
  19.   MX_TIM10_Init();
  20.   MX_TIM2_Init();
  21.   /* USER CODE BEGIN 2 */
  22.         HAL_UART_Receive_IT(&huart3,&rxbuf,1);
  23.         HAL_TIM_PWM_Start(&htim10,TIM_CHANNEL_1);
  24.         HAL_TIM_IC_Start_IT(&htim2,TIM_CHANNEL_1);
  25.         HAL_TIM_IC_Start_IT(&htim2,TIM_CHANNEL_2);
  26.        
  27. //        PWM_ChangeDuty(20);
  28.   /* USER CODE END 2 */

  29.   /* Infinite loop */
  30.   /* USER CODE BEGIN WHILE */
  31.   while (1)
  32.   {

  33.   /* USER CODE END WHILE */

  34.   /* USER CODE BEGIN 3 */
  35.         PWM_ChangeDuty(i);
  36.         HAL_Delay(100);
  37. //        PWM_ChangeDutyTest();
  38.         printf("PWM_Freq is %.4f\n",Freq_Capture);
  39.         printf("PWM_Duty is %.4f\n",PWM_Duty);
  40.         i++;
  41.         if(i>99)
  42.         {
  43.                 i=1;
  44.         }
  45.   }
  46.   /* USER CODE END 3 */

  47. }
复制代码


原理图: 无
仿真: 无
代码: STM32F4_PWM.7z (318.59 KB, 下载次数: 7)





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1