• 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);  
  • 相关阅读:
    Python爬虫之路——简单的网页抓图
    vim修复,telnet安装启动,linux更新软件源
    用博客记录成长的历程
    CleanCode代码整洁之道培训总结(2015-03-14)
    MySQL 登录问题
    LeetCode——Set Matrix Zeroes
    CSS vertical-align属性的使用方法
    电子商务站点设计分析--首屏设计
    easyUI资料学习资料
    java实现DES加密与解密,md5加密
  • 原文地址:https://www.cnblogs.com/penuel/p/11265183.html
Copyright © 2020-2023  润新知