中级会员
 
- 积分
- 466
- 金钱
- 466
- 注册时间
- 2018-6-8
- 在线时间
- 114 小时
|
10金钱
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);/*使能GPIOF时钟*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11,ENABLE);/*使能定时器11时钟*/
GPIO_PinAFConfig(GPIOF,GPIO_PinSource7,GPIO_AF_TIM11);/*复用*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;/*复用*/
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;/*推挽输出*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;/*PF7*/
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;/*上拉*/
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;/**/
GPIO_Init(GPIOF,&GPIO_InitStructure);/*初始化IO*/
TIM_TimeBaseInitStructure.TIM_Period = arr;/*自动重装载*/
TIM_TimeBaseInitStructure.TIM_Prescaler = psc;/*预分频*/
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;/*时钟分频*/
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;/*向上计数*/
TIM_TimeBaseInit(TIM11,&TIM_TimeBaseInitStructure);/*初始化*/
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;/*PWM模式*/
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;/*输出*/
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;/*起始是低*/
TIM_OC1Init(TIM11,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM11,TIM_OCPreload_Enable);/*输出比较预装载使能*/
TIM_ARRPreloadConfig(TIM11,ENABLE);/*自动重载预装载使能*/
TIM_Cmd(TIM11,ENABLE);/*计数使能*/
以上是初始化代码,初始化完成以后,用示波器测试发现波形不正常,
|
|