OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 11159|回复: 2

使用TIM1输出PWM,CH1~3,CH1N~CH3N无输出,CH4正常输出,是什么原因?

[复制链接]

1

主题

3

帖子

0

精华

新手上路

积分
36
金钱
36
注册时间
2014-11-30
在线时间
1 小时
发表于 2014-12-26 19:23:17 | 显示全部楼层 |阅读模式
5金钱
如题,谢谢大家指导~~
[mw_shl_code=c,true]void TIM1_PWM_Init(u32 arr,u32 psc) { //????·??è????????IO???è?? GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; TIM_BDTRInitTypeDef TIM1_BDTRInitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE); //TIM1?±?????? RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); //????PORTB?±?? RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //????PORTA?±?? GPIO_PinAFConfig(GPIOB,GPIO_PinSource13|GPIO_PinSource14|GPIO_PinSource15,GPIO_AF_TIM1); //GPIOB15~13???????¨?±?÷1:CH1N,CH2N,CH3N GPIO_PinAFConfig(GPIOA,GPIO_PinSource8|GPIO_PinSource9|GPIO_PinSource10|GPIO_PinSource11,GPIO_AF_TIM1);//GPIOA8~11???????¨?±?÷1:CH1,CH2,CH3,CH4 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15|GPIO_Pin_13|GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //???????? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //????100MHz GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //???ì???????? GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //???? GPIO_Init(GPIOB,&GPIO_InitStructure); //??????PB13~15 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11; //GPIOF9 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //???????? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //????100MHz GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //???ì???????? GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //???? GPIO_Init(GPIOA,&GPIO_InitStructure); //??????PA8~11 TIM_DeInit(TIM1); TIM_TimeBaseStructure.TIM_Prescaler=psc; //?¨?±?÷·??? TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //?ò?????????? TIM_TimeBaseStructure.TIM_Period=arr; //×?????×°???? TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0; TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);//???????¨?±?÷1 TIM_ARRPreloadConfig(TIM1,ENABLE);//ARPE???? //??????TIM1 Channel~3,Channel1N~3N PWM???? TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //?????¨?±?÷????:TIM?????í???÷??????2 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±??????????? TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;//±??????????? TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; //????????:TIM????±????????? TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //????????:TIM????±????????? TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_Pulse = 200; TIM_OC1Init(TIM1, &TIM_OCInitStructure); //?ù??T???¨???????????????èTIM1OC1 TIM_OC2Init(TIM1, &TIM_OCInitStructure); //?ù??T???¨???????????????èTIM1OC2 TIM_OC3Init(TIM1, &TIM_OCInitStructure); //?ù??T???¨???????????????èTIM1OC3 TIM_OC4Init(TIM1, &TIM_OCInitStructure); //?ù??T???¨???????????????èTIM1OC4 TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable); //????TIM1??CCR1?????¤×°???????÷ TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable); //????TIM1??CCR1?????¤×°???????÷ TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable); //????TIM1??CCR1?????¤×°???????÷ TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable); //????TIM1??CCR1?????¤×°???????÷ TIM1_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; TIM1_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable; TIM1_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF; TIM1_BDTRInitStructure.TIM_DeadTime = 7; TIM1_BDTRInitStructure.TIM_Break = TIM_Break_Disable; TIM1_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High; TIM1_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable; TIM_BDTRConfig(TIM1,&TIM1_BDTRInitStructure); TIM_ARRPreloadConfig(TIM1,ENABLE); TIM_CCPreloadControl(TIM1, ENABLE); TIM_SelectCOM(TIM1,ENABLE); TIM_Cmd(TIM1, ENABLE); //????TIM1 TIM_CtrlPWMOutputs(TIM1, ENABLE); } [/mw_shl_code]

最佳答案

查看完整内容[请看2#楼]

#define GPIO_PinSource8            ((uint8_t)0x08) #define GPIO_PinSource9            ((uint8_t)0x09) #define GPIO_PinSource10           ((uint8_t)0x0A) #define GPIO_PinSource11    & ...
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

230

主题

1950

帖子

10

精华

论坛元老

Rank: 8Rank: 8

积分
4562
金钱
4562
注册时间
2010-12-14
在线时间
32 小时
发表于 2014-12-26 19:23:18 | 显示全部楼层
#define GPIO_PinSource8            ((uint8_t)0x08)
#define GPIO_PinSource9            ((uint8_t)0x09)
#define GPIO_PinSource10           ((uint8_t)0x0A)
#define GPIO_PinSource11           ((uint8_t)0x0B)
至少下面的写法是不对的:
每个宏对应的值不是只设置了某个位,,你想想,你都或,这个值就乱了。。。
 GPIO_PinAFConfig(GPIOA,GPIO_PinSource8|GPIO_PinSource9|GPIO_PinSource10|GPIO_PinSource11,GPIO_AF_TIM1); 
15      
我是开源电子网?网站管理员,对网站有任何问题,请与我联系!QQ:389063473Email:389063473@qq.com
回复

使用道具 举报

1

主题

3

帖子

0

精华

新手上路

积分
36
金钱
36
注册时间
2014-11-30
在线时间
1 小时
 楼主| 发表于 2014-12-26 20:15:45 | 显示全部楼层
回复【2楼】Admin:
---------------------------------
就是这里的问题,修改后就解决了,输出正常,多谢站长~~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2024-11-23 12:59

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表