求助!CH32V203的定時器1TIM1_CH1N_1怎么輸出PWM?沒有看到相關(guān)的開啟教程只找到一個TIM_OC1NPolarityConfig函數(shù)

這是我抄的別人的代碼

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

????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_7;
????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AF_PP;
????GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
????GPIO_Init(?GPIOE,?&GPIO_InitStructure?);
????????????????????????????????????????????????//配置使用的IO

????GPIO_PinRemapConfig(GPIO_FullRemap_TIM1,?ENABLE);????//重映射IO

????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);????//配置核心計數(shù)器工作模式


????TIM_OCInitStructure.TIM_OCMode?=?TIM_OCMode_PWM1;
????TIM_OCInitStructure.TIM_OutputState?=?TIM_OutputState_Enable;
????TIM_OCInitStructure.TIM_Pulse?=?5000;
????TIM_OCInitStructure.TIM_OCPolarity?=?TIM_OCPolarity_High;
????TIM_OC1Init(?TIM1,?&TIM_OCInitStructure?);
?????????????????????????????????????????????????????????//配置比較輸出通道

????TIM_CtrlPWMOutputs(TIM1,?ENABLE?);??????????//高級定時器置位MOE
????TIM_OC1PreloadConfig(?TIM1,?TIM_OCPreload_Disable?);
????TIM_OC1NPolarityConfig(TIM1,?1);
????????????????????????????????????????????????//禁止ccr預(yù)裝載


????TIM_ARRPreloadConfig(?TIM1,?ENABLE?);???????????//開啟核心計數(shù)器自動重裝載


????TIM_Cmd(?TIM1,?ENABLE?);???????//開啟核心計數(shù)器

}







int?main(void)
{

//????u8g2_t??u8g2;
????SetSysClockTo144_HSE();
????led_init();
????PWM_Init();
????TIM1->CH1CVR?=?0;
????TIM3_PWMOut_Init(?100,?48000-1,?50?);
????TIM4_PWMOut_Init(?100,?48000-1,?50?);
????TIM5_PWMOut_Init(?100,?48000-1,?50?);

????while(1)?{
????????led_loop();
????}

}


您好,CH1N為定時器通道1的互補通道,其若要輸出PWM,則需要配合CH1使用,在CH32V203 EVT中有PWM互補輸出的例程,可以參考一下。EVT下載鏈接如下。后續(xù)若有問題,可郵箱(lzs@wch.cn)溝通。

http://www.findthetime.net/downloads/CH32V20xEVT_ZIP.html

?


可以了謝謝



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

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