TA的每日心情 | 开心 2015-12-30 09:00 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]初来乍到
|
求教,G32F207的编码器模式谁用过啊?我用定时器3做的,不知道配置对了没,不过始终采集不懂编码器动作,求看啊!
void TIM3_Configuration(void)
{
TIMER_BaseInitPara TIM_TimeBaseStructure;
/* TIMER1 clock enable */
RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER3,ENABLE);
TIMER_DeInit(TIMER3);
TIM_TimeBaseStructure.TIMER_Prescaler = 0;
TIM_TimeBaseStructure.TIMER_CounterMode = TIMER_COUNTER_UP;
TIM_TimeBaseStructure.TIMER_Period = 0;
TIM_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
TIMER_BaseInit(TIMER3,&TIM_TimeBaseStructure);
TIMER_EncoderInterfaceConfig(TIMER3,TIMER_ENCODER_MODE_TI12,
TIMER_IC_POLARITY_FALLING ,TIMER_IC_POLARITY_FALLING );
TIMER_SetCounter(TIMER3, 1000);
TIMER_Enable(TIMER3, ENABLE);
}
GPIO配置如下:
RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOA,ENABLE);//编码器引脚
GPIO_InitStructure.GPIO_Pin =GPIO_PIN_6 | GPIO_PIN_7;//TIM3 CH1,CH2
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_PIN_4;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUT_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_ResetBits(GPIOA,GPIO_PIN_4); //置低,当编码器地。
读TIMER3 CNT始终无变化
|
|