CH32V307VCT6 基于官方的PWMdemo加了幾個通道,有一個通道一直沒有輸出

程序如下

void?PWM_Init()
{
????GPIO_InitTypeDef?GPIO_InitStructure={0};
????TIM_OCInitTypeDef?TIM_OCInitStructure={0};
????TIM_TimeBaseInitTypeDef?TIM_TimeBaseInitStructure={0};

????RCC_APB2PeriphClockCmd(?RCC_APB2Periph_GPIOA?|?RCC_APB2Periph_TIM1,?ENABLE?);

????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_8;
????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AF_PP;
????GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
????GPIO_Init(?GPIOA,?&GPIO_InitStructure?);
????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_9;
????GPIO_Init(?GPIOA,?&GPIO_InitStructure?);
????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_10;
????GPIO_Init(?GPIOA,?&GPIO_InitStructure?);
????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_11;
????GPIO_Init(?GPIOA,?&GPIO_InitStructure?);

????TIM_TimeBaseInitStructure.TIM_Period?=?10000;
????TIM_TimeBaseInitStructure.TIM_Prescaler?=?0;
????TIM_TimeBaseInitStructure.TIM_ClockDivision?=?TIM_CKD_DIV1;
????TIM_TimeBaseInitStructure.TIM_CounterMode?=?TIM_CounterMode_CenterAligned1;
????TIM_TimeBaseInit(?TIM1,?&TIM_TimeBaseInitStructure);


????TIM_OCInitStructure.TIM_OCMode?=?TIM_OCMode_PWM1;


????TIM_OCInitStructure.TIM_OutputState?=?TIM_OutputState_Enable;
????TIM_OCInitStructure.TIM_Pulse?=?3000;
????TIM_OCInitStructure.TIM_OCPolarity?=?TIM_OCPolarity_High;
????TIM_OC1Init(?TIM1,?&TIM_OCInitStructure?);
????TIM_OC2Init(?TIM1,?&TIM_OCInitStructure?);
????TIM_OC3Init(?TIM1,?&TIM_OCInitStructure?);
????TIM_OC4Init(?TIM1,?&TIM_OCInitStructure?);

????TIM_CtrlPWMOutputs(TIM1,?ENABLE?);
????TIM_OC1PreloadConfig(?TIM1,?TIM_OCPreload_Disable?);
????TIM_OC2PreloadConfig(?TIM1,?TIM_OCPreload_Disable?);
????TIM_OC3PreloadConfig(?TIM1,?TIM_OCPreload_Disable?);
????TIM_OC4PreloadConfig(?TIM1,?TIM_OCPreload_Disable?);
????TIM_ARRPreloadConfig(?TIM1,?ENABLE?);
????TIM_Cmd(?TIM1,?ENABLE?);

}



int?main(void)
{
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	SystemCoreClockUpdate();
	Delay_Init();
	USART_Printf_Init(115200);	
	printf("SystemClk:%d\r\n",SystemCoreClock);
	printf(?"ChipID:%08x\r\n",?DBGMCU_GetCHIPID()?);
	printf("This?is?printf?example\r\n");

	PWM_Init();
	TIM1->CH1CVR?=?2000;
	TIM1->CH2CVR?=?4000;
	TIM1->CH3CVR?=?6000;
	TIM1->CH4CVR?=?8000;

	while(1)
????{

	}
}

波形如圖


微信截圖_20230316185128.png

注意此通道和你的打印串口(TX)腳(PA9)沖突了


好家伙沒注意


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

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