码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-07-29 17:33:17      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:ocp   output   clock   rip   struct   init   isa   polar   counter   

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输出

标签:ocp   output   clock   rip   struct   init   isa   polar   counter   

原文地址:https://www.cnblogs.com/penuel/p/11265183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!