【求助】CH32V307 TIM3 PWM無輸出

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?);


我將

GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_Out_PP;

改為

GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AF_PP;

PWM能正常輸出

查看芯片文檔,發(fā)現(xiàn)TIM3屬于片上外設(shè),走復(fù)用通道,所以必須使用AF_PP

image.png


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频