如题,要用TIM1从PB1输出PWM,查看数据手册,PB1支持TIM1_CH3N互补输出,部分复用,代码如下,为啥没输出?
GPIO_InitTypeDef?GPIO_InitStructure={0}; TIM_OCInitTypeDef?TIM_OCInitStructure={0}; TIM_TimeBaseInitTypeDef?TIM_TimeBaseInitStructure={0}; RCC_APB2PeriphClockCmd(?RCC_APB2Periph_AFIO?|?RCC_APB2Periph_GPIOB?|?RCC_APB2Periph_TIM1,?ENABLE?); GPIO_PinRemapConfig(GPIO_PartialRemap_TIM1,?ENABLE); GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_1; 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_PWM2; #endif TIM_OCInitStructure.TIM_OutputState?=?TIM_OutputState_Disable; TIM_OCInitStructure.TIM_OCPolarity?=?TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCIdleState?=?TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_OutputNState?=?TIM_OutputNState_Enable; TIM_OCInitStructure.TIM_OCNPolarity?=?TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCNIdleState?=?TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_Pulse?=?ccp; TIM_OC3Init(TIM1,?&TIM_OCInitStructure?); TIM_CtrlPWMOutputs(TIM1,?ENABLE?); TIM_OC3PreloadConfig(?TIM1,?TIM_OCPreload_Enable?); TIM_ARRPreloadConfig(?TIM1,?ENABLE?); TIM_Cmd(?TIM1,?ENABLE?);
有输出,是我的开发板有问题,谢谢。
热门产品 :
CH32V317: 互联型青稞RISC-V MCU