標(biāo)題:
STM32正交編碼器AB相配置
[打印本頁]
作者:
491621
時間:
2019-11-9 16:09
標(biāo)題:
STM32正交編碼器AB相配置
static void TIM4_Mode_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/*正交編碼器輸入引腳*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/*- TIM編碼器模式配置-*/
TIM_DeInit(TIM4);
TIM_TimeBaseStructure.TIM_Period = Parameter * 2; //u16 Parameter = 512;輸入編碼器線數(shù)
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision =TIM_CKD_DIV1 ;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM4, TIM_EncoderMode_TI1, TIM_ICPolarity_Rising ,TIM_ICPolarity_Rising); //配置編碼器模式3,即觸發(fā)源和極性
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter = 6;
TIM_ICInit(TIM4, &TIM_ICInitStructure);
TIM4->CNT = 0;
TIM_Cmd(TIM4, ENABLE); //啟動TIM4定時器
}
void TIM4_Init(void)
{
TIM4_Mode_Config();
}
作者:
ferry21
時間:
2019-12-4 09:44
有完整代碼嗎
作者:
491621
時間:
2020-4-23 12:03
標(biāo)題:
RE: STM32正交編碼器AB相配置
STM32 正交編碼器AB相配置.7z
(182.82 KB, 下載次數(shù): 58)
2020-5-15 03:20 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1