STEP1:Cài đặt timer 1 internal clock

PWM1

STEP2:Cấu hình PWM OUTPUT

PWM2

STEP3:Cài đặt thông số PWM

PWM3

72MHz / [(7199+1)*(499+1)]=20Hz

STEP4:Cấu hình thạch anh 72Mhz

PWM4

STEP 5:CODE Biên dịch

  • intmain(void)
  • {
  • /* USER CODE BEGIN 1 */
  • /* USER CODE END 1*/
  • /* MCU Configuration———————————————————-*/
  • /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  • HAL_Init();
  • /* Configure the system clock */
  • SystemClock_Config();
  • /* Initialize all configured peripherals */
  • MX_GPIO_Init();
  • MX_TIM2_Init();
  • /* USER CODE BEGIN 2 */
  • HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);
  • HAL_TIM_PWM_Start(&htim1 TIM_CHANNEL_4);
  • __HAL_TIM_SetCompare(&htim1, TIM_CHANNEL_4, 250);
  • /* USER CODE END 2*/
  • /* Infinite loop */
  • /* USER CODE BEGIN WHILE */
  • while(1)
  • {
  • /* USER CODE END WHILE */
  • /* USER CODE BEGIN 3 */
  • }
  • /* USER CODE END 3*/

Bình luận

Bình luận