CH32V203C8的TIM 2 3 4pwm功能不能使用是什么原因

用BSP里的TIM1 PWM程序改的,只有TIM1有輸出,其他的都沒有輸出是什么原因

void TIM1_PWMOut_Init(u16 arr, u16 psc, u16 ccp)

{

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; //設(shè)置PA8為復(fù)用推挽輸出

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init( GPIOA, &GPIO_InitStructure );


TIM_TimeBaseInitStructure.TIM_Period = arr; //指定在下次更新事件時加載到活動自動重新加載寄存ARR中的周期值。

TIM_TimeBaseInitStructure.TIM_Prescaler = psc;//指定用于分割TIM時鐘的預(yù)分頻值。

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_Enable;

TIM_OCInitStructure.TIM_Pulse = ccp; //設(shè)置占空比大小

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OC1Init( TIM1, &TIM_OCInitStructure );


TIM_CtrlPWMOutputs(TIM1, ENABLE );

TIM_OC1PreloadConfig( TIM1, TIM_OCPreload_Disable );

TIM_ARRPreloadConfig( TIM1, ENABLE );

TIM_Cmd( TIM1, ENABLE );

}


void TIM4_PWMOut_Init(u16 arr, u16 psc, u16 ccp)

{

? ? 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_TIM4, ENABLE);


? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //設(shè)置PB6為復(fù)用推挽輸出

? ? 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; //指定在下次更新事件時加載到活動自動重新加載寄存ARR中的周期值。

? ? TIM_TimeBaseInitStructure.TIM_Prescaler = psc;//指定用于分割TIM時鐘的預(yù)分頻值。

? ? TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;

? ? TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;

? ? TIM_TimeBaseInit( TIM4, &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_Enable;

? ? TIM_OCInitStructure.TIM_Pulse = ccp; //設(shè)置占空比大小

? ? TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

? ? TIM_OC1Init( TIM4, &TIM_OCInitStructure );


? ? TIM_CtrlPWMOutputs(TIM4, ENABLE );

? ? TIM_OC1PreloadConfig( TIM4, TIM_OCPreload_Disable );

? ? TIM_ARRPreloadConfig( TIM4, ENABLE );

? ? TIM_Cmd( TIM4, ENABLE );

}


?


您好,附件為TIM2、3、4 PWM輸出例程,可以參考一下。后續(xù)若有問題,可通過郵箱和我溝通

icon_rar.gifCH32V203C8T6 TIM2-3-4 PWM.zip



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

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