Advertisement

hal库如何输出PWM Generation CH1N互补波形输出

阅读量:

首先配置cubeMX选项:

在这里插入图片描述

设置分频系数和计数个数,,使能自动重装载

在这里插入图片描述

初始化程序中启动通道pwm输出:

复制代码
    	HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
    	HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);
    	HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_3);
    	//设置pwm占空比值
    	htim1.Instance->CCR1 = 480;
    	htim1.Instance->CCR2 = 480;
    	htim1.Instance->CCR3 = 480;

请了解启动功能模块的操作流程。(与正向PWM启动功能模块类似)HAL_StatusTypeDef HAL.TIM_PWM_Start(...)的具体实现需严格按照文档规定操作;若选用错误的...

复制代码
    /** * @brief  Starts the PWM signal generation on the complementary output.
      * @param  htim TIM handle
      * @param  Channel TIM Channel to be enabled
      *          This parameter can be one of the following values:
      *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
      *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
      *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
      * @retval HAL status
      */
    HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
    {
      uint32_t tmpsmcr;
    
      /* Check the parameters */
      assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
    
      /* Enable the complementary PWM output  */
      TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
    
      /* Enable the Main Output */
      __HAL_TIM_MOE_ENABLE(htim);
    
      /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
      tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
      if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
      {
    __HAL_TIM_ENABLE(htim);
      }
    
      /* Return function status */
      return HAL_OK;
    }

全部评论 (0)

还没有任何评论哟~