初级会员

- 积分
- 136
- 金钱
- 136
- 注册时间
- 2018-3-26
- 在线时间
- 287 小时
|
20金钱
请教大家和原子哥,关于光栅尺读数的问题,光栅尺输出的是差分信号,需要用单片机TIM的编码器模式进行采集,在采集的时候发现一个问题,当我微微移动时,有读数正常,但是快速移动时,读数就没啥变化,就像是反应不过来,用示波器看了波形没问题
- void EncoderA_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure; // ?????????
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; // ??????????
- TIM_ICInitTypeDef TIM_ICInitStructure; // ???????????????
-
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); // ??TIM4??
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // ??GPIOB??
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1; // PB6?PB7
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; // ????
- GPIO_Init(GPIOA, &GPIO_InitStructure); // ??GPIO_InitStructure??????GPIOB0
- TIM_TimeBaseStructure.TIM_Period = 0xffff; // ??????????
- TIM_TimeBaseStructure.TIM_Prescaler = 0; // ????
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; // ??????:???
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; // TIM??????
- TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); // ??TIM_TimeBaseInitStruct?????????TIM4
-
- TIM_EncoderInterfaceConfig(TIM2, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);//???????3:CH1?CH2????,???
-
- //???TIM4??????
- TIM_ICStructInit(&TIM_ICInitStructure); // ?TIM_ICInitStruct ?????????????
- TIM_ICInitStructure.TIM_ICFilter = 0x00; // IC1F=0011 ???????(??????)
- TIM_ICInit(TIM2, &TIM_ICInitStructure); // ?TIM_ICInitStructure????????TIM4?????
- TIM_Cmd(TIM2, ENABLE); // ?????4
- }
- uint32_t read_encoder(void)
- {
-
- return TIM2->CNT;
-
- }
- while(1)
- {
- encoder_num=TIM2->CNT;
- printf("±àÂëÆ÷êy¾YêÇ%d\r\n",encoder_num);
-
- }
复制代码
|
|