想要利用定時器輸出PWM波,初始化函數(shù)如下
void?test_init(void) { ????RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,?ENABLE); ????RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,?ENABLE); ????TIM_InternalClockConfig(TIM1);//選擇內(nèi)部時鐘源 ????//初始化GPIO口 ????GPIO_InitTypeDef?GPIO_InitStructure; ????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AF_PP; ????GPIO_InitStructure.GPIO_Pin?=?LED_3_GPIOpin|LED_4_GPIOpin; ????GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz; ????GPIO_Init(GPIOC,?&GPIO_InitStructure); ????//始化驅(qū)動LED的PWM波,使用定時器TIM1 ????TIM_TimeBaseInitTypeDef?TIM_TimeBaseInitStructure; ????TIM_TimeBaseStructInit(&TIM_TimeBaseInitStructure); ????TIM_TimeBaseInitStructure.TIM_ClockDivision?=?TIM_CKD_DIV1; ????TIM_TimeBaseInitStructure.TIM_CounterMode?=?TIM_CounterMode_Up; ????TIM_TimeBaseInitStructure.TIM_Period?=?100?-?1;?????//ARR ????TIM_TimeBaseInitStructure.TIM_Prescaler?=?9?-?1;??????//PSC???8M?Hz ????TIM_TimeBaseInitStructure.TIM_RepetitionCounter?=?0; ????TIM_TimeBaseInit(TIM1,?&TIM_TimeBaseInitStructure); ????TIM_OCInitTypeDef?TIM_OCInitStructure; ????TIM_OCStructInit(&TIM_OCInitStructure); ????TIM_OCInitStructure.TIM_OCMode?=?TIM_OCMode_PWM1; ????TIM_OCInitStructure.TIM_OCPolarity?=?TIM_OCPolarity_High; ????TIM_OCInitStructure.TIM_OutputState?=?TIM_OutputState_Enable; ????TIM_OCInitStructure.TIM_Pulse?=?0;??????//CCR ????TIM_OC3Init(TIM1,?&TIM_OCInitStructure);//CH3通道 ????TIM_OC4Init(TIM1,?&TIM_OCInitStructure);//CH3通道 ????TIM_Cmd(TIM1,?ENABLE); } void?test_pwm_set(uint16_t?Compare) { ????TIM_SetCompare3(TIM1,?Compare); ????TIM_SetCompare4(TIM1,?Compare); }
在主函數(shù)調(diào)用init初始化后,在while循環(huán)中更改占空比,利用示波器測相應(yīng)管腳均為低電平,LED也未能實現(xiàn)呼吸閃爍
利用相同初始化流程,利用TIM2在PC0(ch3通道)能正常輸出PWM
不知道為啥這個TIM1總是無法輸出PWM。
嘗試過更換板子,但沒有改善(莫非是風槍溫度高了把TIM1外設(shè)給烤沒了?,但兩塊板子都是TIM1有問題TIM2正常
求助!