用TIM1产生PWM 无波形输出 仿真器TIM1->CCR1一直是初始值不变且不为0(占空比在变的情况下)

2019-08-23 16:07发布

[mw_shl_code=c,true]void Timer1_configuration() { GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM1_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; TIM_DeInit(TIM1); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA| RCC_APB2Periph_AFIO|RCC_APB2Periph_TIM1, ENABLE); //****** TIM1 CH1(PA8) ****************************** GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //???????ê???? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); TIM1_TimeBaseStructure.TIM_Period = 7200-1; // 0xFFFF; ???????? !@#$%^&*()~ TIM1_TimeBaseStructure.TIM_Prescaler = 10-1; //0xF; ·??? TIM1_TimeBaseStructure.TIM_ClockDivision = 0x0; TIM1_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM1_TimeBaseStructure.TIM_RepetitionCounter= 0x00; //?è?????????????÷??;RCR?ò???????÷??????????0???á?ú?ú !@#$%^&*()~ //?????ü?????????????÷??????RCR???¨N?©????????????????? TIM_TimeBaseInit(TIM1,&TIM1_TimeBaseStructure); // ????×????±??????72MHz,????=72M/(36000-1+1)/1000 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; TIM_OCInitStructure.TIM_Pulse = 4000; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; //TIM_OCInitStructure.TIM_OCIdleState=TIM_OCIdleState_Reset; //TIM_OCInitStructure.TIM_OCNIdleState=TIM_OCNIdleState_Reset; TIM_OC1Init(TIM1,&TIM_OCInitStructure); //TIM_OC4Init(TIM1,&TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable); // TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable); TIM_ARRPreloadConfig(TIM1, ENABLE); TIM_Cmd(TIM1,ENABLE); TIM_CtrlPWMOutputs(TIM1,ENABLE); } [/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
6条回答
正点原子
1楼-- · 2019-08-23 18:25
CCR1为什么要变?
建议楼主好好再看看PWM的原理。
taizonglai
2楼-- · 2019-08-23 22:31
你的CCR1没有写值吧。CCR1不写值你的占空比肯定变不了的吧。 用TIM_SetCompare2(TIM_TypeDef* TIMx, uint16_t Compare2)赋个占空比试试
静心潜力
3楼-- · 2019-08-24 01:12
回复【2楼】正点原子:
---------------------------------
我是用来改变输出的脉宽啊
静心潜力
4楼-- · 2019-08-24 01:53
回复【3楼】zuozhongkai:
---------------------------------
我就是用这函数改占空比...
正点原子
5楼-- · 2019-08-24 06:58
 精彩回答 2  元偷偷看……
yysforever
6楼-- · 2019-08-24 07:25
请问下,CCR1的值需要减1吧

一周热门 更多>