PB0、PB1作為PWM輸出,但是用邏輯分析儀測試后沒有信號。不知道是不是TIM3的CH1、CH2引腳PA6、PA7被USART1占用影響。定時器初始化代碼如下:
????GPIO_InitTypeDef?GPIO_InitStructure={0}; ????TIM_OCInitTypeDef?TIM_OCInitStructure={0}; ????TIM_TimeBaseInitTypeDef?TIM_TimeBaseInitStructure={0}; ????RCC_APB2PeriphClockCmd(?RCC_APB2Periph_GPIOB,?ENABLE?); ????RCC_APB1PeriphClockCmd(?RCC_APB1Periph_TIM3,?ENABLE?); //????GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3,?ENABLE); ????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_0?|?GPIO_Pin_1; ????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_Out_PP; ????GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz; ????GPIO_Init(?GPIOB,?&GPIO_InitStructure?); ????GPIO_SetBits(GPIOB,?GPIO_Pin_0); ????GPIO_ResetBits(GPIOB,?GPIO_Pin_1); ????TIM_InternalClockConfig(TIM3); ????TIM_TimeBaseInitStructure.TIM_Period?=?2000;//SystemCoreClock/HeatFreq-1; ????TIM_TimeBaseInitStructure.TIM_Prescaler?=?95; ????TIM_TimeBaseInitStructure.TIM_ClockDivision?=?TIM_CKD_DIV1; ????TIM_TimeBaseInitStructure.TIM_CounterMode?=?TIM_CounterMode_Up; ????TIM_TimeBaseInit(?TIM3,?&TIM_TimeBaseInitStructure); ????TIM_OCInitStructure.TIM_OCMode?=?TIM_OCMode_PWM1; ????TIM_OCInitStructure.TIM_OutputState?=?TIM_OutputState_Enable; ????TIM_OCInitStructure.TIM_Pulse?=?1000; ????TIM_OCInitStructure.TIM_OCPolarity?=?TIM_OCPolarity_High; ????TIM_OC3Init(?TIM3,?&TIM_OCInitStructure?); ????TIM_OCInitStructure.TIM_OCMode?=?TIM_OCMode_PWM1; ????TIM_OCInitStructure.TIM_OutputState?=?TIM_OutputState_Enable; ????TIM_OCInitStructure.TIM_Pulse?=?0; ????TIM_OCInitStructure.TIM_OCPolarity?=?TIM_OCPolarity_High; ????TIM_OC4Init(?TIM3,?&TIM_OCInitStructure?); ????TIM_CtrlPWMOutputs(TIM3,?ENABLE?); //????TIM_OC3PreloadConfig(?TIM3,?TIM_OCPreload_Disable?); //????TIM_OC4PreloadConfig(?TIM3,?TIM_OCPreload_Disable?); //????TIM_ARRPreloadConfig(?TIM3,?ENABLE?); ????TIM_Cmd(?TIM3,?ENABLE?);
熱門產(chǎn)品 :
CH339: 7端口多功能USB HUB控制器芯片