初级会员 
  
	- 积分
 - 124
 
        - 金钱
 - 124 
 
       - 注册时间
 - 2018-3-26
 
      - 在线时间
 - 288 小时
 
 
 
 | 
 
30金钱 
请教一下大家,关于STM32F103编码器的问题 
- void TIM3_Mode_Config(void)
 
 - {
 
 -         //u16 CCR1_Val = 2500;
 
 -         //u16 CCR2_Val = 1000;
 
 -         GPIO_InitTypeDef GPIO_InitStructure;
 
 -   TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 
 -         TIM_ICInitTypeDef TIM_ICInitStructure;
 
 -         //TIM_OCInitTypeDef  TIM_OCInitStructure;
 
 -         
 
 - /*----------------------------------------------------------------*/
 
 -         
 
 -         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
 
 -   
 
 -         
 
 -   GPIO_StructInit(&GPIO_InitStructure);
 
 -   /* Configure PA.06,07 as encoder input */
 
 -   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
 
 -   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
 
 -   GPIO_Init(GPIOA, &GPIO_InitStructure);
 
 -         
 
 - /*----------------------------------------------------------------*/        
 
  
-         
 
 -   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ê1Äü£Ô£é£í£3
 
 -         TIM_DeInit(TIM3);
 
 -         TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
 
 -         
 
 -   TIM_TimeBaseStructure.TIM_Period =0xffff;       //
 
 -   TIM_TimeBaseStructure.TIM_Prescaler =0;            //éèÖÃÔ¤·ÖÆμ£o
 
 -   TIM_TimeBaseStructure.TIM_ClockDivision =TIM_CKD_DIV1 ;        //éèÖÃê±Öó·ÖÆμÏμêy£o2»·ÖÆμ
 
 -   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //ÏòéϼÆêyÄ£ê½
 
 -   //TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1; 
 
 -         /*3õê¼»ˉTIM2¶¨ê±Æ÷ */
 
 -   TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
 
 -         
 
 -         /*-----------------------------------------------------------------*/
 
 -         //±àÂëÅäÖà                       ±àÂëÄ£ê½
 
 -         TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, 
 
 -                              TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);  //TIM_ICPolarity_RisingéÏéyÑØ2¶»ñ
 
 -   TIM_ICStructInit(&TIM_ICInitStructure);
 
 -   TIM_ICInitStructure.TIM_ICFilter = 6;         //±è½ÏÂË2¨Æ÷
 
 -   TIM_ICInit(TIM3, &TIM_ICInitStructure);
 
 -   
 
 -   TIM_ClearFlag(TIM3, TIM_FLAG_Update);
 
 -   TIM_ITConfig(TIM3, TIM_IT_Update, DISABLE);   //ê1ÄüÖD¶Ï
 
 -   //Reset counter
 
 -   TIM3->CNT =0;
 
 -         
 
 -         
 
 -         TIM_Cmd(TIM3, ENABLE);   //ê1Äü¶¨ê±Æ÷3
 
 - }
 
 - void TIM_Init(void)
 
 - {
 
 -   TIM3_Mode_Config();
 
 - }
 
 
  复制代码-    if((TIM3->CR1 & TIM_CounterMode_Down) != TIM_CounterMode_Down)
 
 -                         {
 
 -                         printf("1\r\n");
 
 -                         }
 
 -                         else{
 
 -                         printf("0\r\n");
 
 -                         }
 
  复制代码 无论正向还是反向,都只输出1,这是为什么?识别不了方向 
 |   
 
 
最佳答案
查看完整内容[请看2#楼] 
http://www.openedv.com/forum.php?mod=viewthread&tid=301406&extra= 
 
 
 
 
 
 
 |