ch32f10x的tim1 pwm ch2N通道无输出,帮忙看看是哪里没有配置到位
void TIM1_PWMOut_Init( u16 arr, u16 psc, u16 ccp )
{
	GPIO_InitTypeDef GPIO_InitStructure;
	TIM_OCInitTypeDef TIM_OCInitStructure;
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
	
	RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_TIM1 , ENABLE );

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init( GPIOB, &GPIO_InitStructure );
	
	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( TIM1, &TIM_TimeBaseInitStructure);	

#if (PWM_MODE == PWM_MODE1)
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;	
	
#elif (PWM_MODE == PWM_MODE2)	
	TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;	
	
#endif
	
	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;		
	TIM_OCInitStructure.TIM_Pulse = ccp;	
	//TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
	TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCPolarity_High;
	TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;	
	TIM_OC2Init( TIM1, &TIM_OCInitStructure );  

	TIM_CtrlPWMOutputs(TIM1, ENABLE );

	TIM_OC2PreloadConfig( TIM1, TIM_OCPreload_Disable );
	TIM_ARRPreloadConfig( TIM1, ENABLE );		
	TIM_Cmd( TIM1, ENABLE );
}


您好,若你只需要CH2N输出波形,在进行TIM初始化配置的时候也需要对原输出通道进行配置,不能只对互补通道进行配置,具体程序可见附件参考例程。

icon_rar.gifCH32F10x.zip



只有登录才能回复,可以选择微信账号登录