求助求助STM32F4 TIM2 CH3 PWM无波形

2019-07-20 09:27发布

void OV7670_XCLK(u32 arr,u32 psc)                               //arr=7-1,psc=1-1
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);   //TIM2时钟使能
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);  //使能PB时钟

GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_TIM2); //GPIOB10复用TIM2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;           
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;        
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;     
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;        
GPIO_Init(GPIOB,&GPIO_InitStructure);                //PB10初始化         
   
TIM_TimeBaseStructure.TIM_Prescaler=psc;  //分频=0
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数
TIM_TimeBaseStructure.TIM_Period=arr;   //重载值为6
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;

TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);//初始化TIM2

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //PWM模式2
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //比较使能输出
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //极性为低
TIM_OC3Init(TIM2, &TIM_OCInitStructure);  //初始化 TIM2 OC3
TIM_SetCompare3(TIM2,3);  //比较寄存器3赋值为3
TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);  //使能CCR3

  TIM_ARRPreloadConfig(TIM2,ENABLE);//ARPE使能

TIM_Cmd(TIM2, ENABLE);  //使能TIM2

}


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。