PWM脉冲程序.docx

  1. 1、本文档共7页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
PWM脉冲程序

一个定时器四个通道,分别产生不同频率(这个例子网上也有)vu16 CCR1_Val = 32768;vu16 CCR2_Val = 16384;vu16 CCR3_Val = 8192;vu16 CCR4_Val = 4096;void TIM_Configuration(void){TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;TIM_OCInitTypeDef TIM_OCInitStructure;RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);TIM_TimeBaseStructure.TIM_Period = 65535;TIM_TimeBaseStructure.TIM_Prescaler = 2;TIM_TimeBaseStructure.TIM_ClockDivision = 0;?TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;TIM_TimeBaseInit(TIM2, TIM_TimeBaseStructure);TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;??????//PWM模式2TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //正向通道有效TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;//反向通道无效TIM_OCInitStructure.TIM_Pulse = CCR1_Val;????????//占空时间TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;????//输出极性TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;????//互补端的极性TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;TIM_OC1Init(TIM2,TIM_OCInitStructure);????????//通道1TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable);TIM_OCInitStructure.TIM_Pulse = CCR2_Val;????????//占空时间TIM_OC2Init(TIM2,TIM_OCInitStructure);????????//通道2TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Disable);TIM_OCInitStructure.TIM_Pulse = CCR3_Val;????????//占空时间TIM_OC3Init(TIM2,TIM_OCInitStructure);????????//通道3TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Disable);TIM_OCInitStructure.TIM_Pulse = CCR4_Val;????????//占空时间TIM_OC4Init(TIM2,TIM_OCInitStructure);????????//通道4TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Disable);TIM_Cmd(TIM2,ENABLE);//TIM_CtrlPWMOutputs(TIM2,ENABLE);?TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4, ENABLE);}void GPIO_Configuration(void){GPIO_InitTypeDef GPIO_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档