CH32V307 定時(shí)器輸出翻轉(zhuǎn)模式

??? GPIO_InitTypeDef GPIO_InitStructure={0};
??? NVIC_InitTypeDef NVIC_InitStructure = {0};
??? TIM_OCInitTypeDef TIM_OCInitStructure={0};
??? TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure={0};

??? RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_TIM8 | RCC_APB2Periph_AFIO, ENABLE );

??? GPIO_PinRemapConfig(GPIO_Remap_TIM8 , ENABLE);

??? GPIO_InitStructure.GPIO_Pin = X_PUL_GPIO;
??? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
??? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
??? GPIO_Init( X_PUL_PORT, &GPIO_InitStructure );

??? TIM_TimeBaseInitStructure.TIM_Period = PWM_ARR;???? /* 自動(dòng)重裝載值 */
??? TIM_TimeBaseInitStructure.TIM_Prescaler = PWM_PSC;? /* 定時(shí)器分頻 */
??? TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
??? TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
??? TIM_TimeBaseInit( X_TIM, &TIM_TimeBaseInitStructure);

??? TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
??? TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
??? TIM_OCInitStructure.TIM_Pulse = PWM_PLU;
??? TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
??? TIM_OC3Init( X_TIM, &TIM_OCInitStructure );

??? TIM_CtrlPWMOutputs(X_TIM, DISABLE );
??? TIM_OC3PreloadConfig( X_TIM, TIM_OCPreload_Disable );
??? TIM_ARRPreloadConfig( X_TIM, ENABLE );
??? TIM_Cmd( X_TIM, ENABLE );
??? TIM_ITConfig(X_TIM, TIM_IT_CC3, DISABLE);

??? NVIC_InitStructure.NVIC_IRQChannel = TIM8_CC_IRQn;
??? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
??? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
??? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
??? NVIC_Init(&NVIC_InitStructure);


開中斷

??? TIM_ITConfig(X_TIM, TIM_IT_CC3, ENABLE);

這樣配置對(duì)面?中斷里面設(shè)置比較值沒有用?
??????? Tim_Count = TIM_GetCounter(X_TIM);
??????? tmp = 0xFFFF & (Tim_Count + g_toggle_pulse);
??????? printf("tmP = %d\r\n",tmp);
??????? TIM_SetCompare3(X_TIM,tmp);//修改占空比



有例程嗎?

您好,若程序中使用了中斷函數(shù),注意要加中斷聲明,如下圖。附件為參考例程,可以參考一下

icon_rar.gifCH32V307 TIM翻轉(zhuǎn)模式.zip

image.png


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

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