7_STM32cubeIDE_並行構建項目,手冊翻譯,TIM(定時器)

1_並行構建項目


並行構建項目能夠減小構建時間。(stm32cubeIDE默認並行編譯)bash

2_手冊翻譯


請參考這個視頻ide

3_TIM(定時器)


3.1_PWM呼吸燈

PWM 的週期就是 16MHz/(15+1)/(99+1) = 10kHzoop

int main(void)
{
  /* USER CODE BEGIN 1 */
uint16_t pwm_val=0;
  /* USER CODE END 1 */
  

  /* MCU Configuration--------------------------------------------------------*/

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

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_TIM1_Init();
  /* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);//使能PWM
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
	  while(pwm_val<50){
		 pwm_val++;
		 __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1,pwm_val); //設置佔空比
		 HAL_Delay(50);
	  }
	  
	  while(pwm_val){
			 pwm_val--;
			 __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1,pwm_val);
			 HAL_Delay(50);
		  }
	  
  }
  /* USER CODE END 3 */
}
複製代碼

相關文章
相關標籤/搜索