關(guān)于CH32V307VC的AB相編碼器配置問題?。?!

---PC6接A相? PC7接B相


---目前遇到的問題是,無論編碼器正轉(zhuǎn)還是反轉(zhuǎn),計數(shù)值都是從65535向下計數(shù)!??!


下面是配置代碼,(RCC使能已開)

// TIM8 Encoder? PC6 AND PC7

? ? TIM_TimeBaseStructInit(&TIM_TimeBaseInitStructure);

? ? TIM_TimeBaseInitStructure.TIM_Period = 0xFFFF;

? ? TIM_TimeBaseInitStructure.TIM_Prescaler = 1;

? ? TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;

? ? TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;

? ? TIM_TimeBaseInitStructure.TIM_RepetitionCounter =? 0x00;

? ? TIM_TimeBaseInit(TIM8, &TIM_TimeBaseInitStructure);


? ? TIM_EncoderInterfaceConfig(TIM8, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);


? ? TIM_ICStructInit(&TIM_ICInitStructure);

? ? TIM_ICInitStructure.TIM_Channel = TIM_Channel_1 | TIM_Channel_2;

? ? TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

? ? TIM_ICInitStructure.TIM_ICFilter = 0; // 濾波

? ? TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

? ? TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

? ? TIM_ICInit(TIM8, &TIM_ICInitStructure);

/*

? ? TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;

? ? TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

? ? TIM_ICInitStructure.TIM_ICFilter = 0; // 濾波

? ? TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

? ? TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

? ? TIM_ICInit(TIM8, &TIM_ICInitStructure);

*/

? ? TIM_ClearFlag(TIM8, TIM_FLAG_Update);? ? ? ? //清除TIM更新標(biāo)志位

? ? TIM_ITConfig(TIM8, TIM_IT_Update, ENABLE);? ?//使能開啟TIM中斷

? ? TIM_SetCounter(TIM8, 0);

? ? TIM_Cmd(TIM8, ENABLE);


使用的編碼器如下:

微信圖片_20230731154414.jpg


熱門產(chǎn)品 : USB3.0 HUB控制器:CH634

你好,附件為編碼器例程,可參考下,如測試有問題建議檢查下硬件。

icon_rar.gifCH32V307 電機測速-AB編碼器.zip



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

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