STM32F0库函数初始化系列:PWM输出

Posted penuel

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STM32F0库函数初始化系列:PWM输出相关的知识,希望对你有一定的参考价值。

void TIM1_Configuration(void)

  TIM_TimeBaseInitTypeDef TIM_Time1BaseStructure;
  TIM_OCInitTypeDef TIM_OCInitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

  /* Time 定时基础设置*/
  TIM_Time1BaseStructure.TIM_Prescaler = 0;
  TIM_Time1BaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  /* Time 定时设置为上升沿计算模式*/
  TIM_Time1BaseStructure.TIM_Period = (SystemCoreClock / 40000)-1;
  TIM_Time1BaseStructure.TIM_ClockDivision = 0;
  TIM_Time1BaseStructure.TIM_RepetitionCounter = 0;
 
  TIM_TimeBaseInit(TIM1, &TIM_Time1BaseStructure);
 
  /* 频道1,2,3,4的PWM 模式设置 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable ;//TIM_OutputState_Enable; //PWM输出使能位
  TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable ;//TIM_OutputNState_Enable; //互补PWM输出使能位
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;  //PWM 1为有效电平
  TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; //PWM互补 0为有效电平
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
  TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
 
  TIM_OCInitStructure.TIM_Pulse = 600-1; //赋占空比值
  TIM_OC2Init(TIM1, &TIM_OCInitStructure);//使能频道2配置
 
  /* TIM1 计算器使能*/
  TIM_Cmd(TIM1, DISABLE);
     
  /* TIM1 主输出使能 */
  TIM_CtrlPWMOutputs(TIM1, DISABLE);  

 

以上是关于STM32F0库函数初始化系列:PWM输出的主要内容,如果未能解决你的问题,请参考以下文章

STM32F103 PWM输出实验(HAL库)

STM32F0 中 ADC 多通道转换结果相同的问题

使用STM32CubeMX初始化STM32F031F6Px系列

STM32F0使用LL库实现UART接收

STM32F4库函数初始化系列:串口DMA接收

STM32F103五分钟入门系列(十五)输出比较(PWM输出)+各类测试