cancel
Showing results for 
Search instead for 
Did you mean: 

Encoder interface

muralisridhar
Associate II
Posted on September 24, 2009 at 17:06

Encoder interface

2 REPLIES 2
tomas23
Associate II
Posted on May 17, 2011 at 13:24

The internal clock, according to block diagram, goes to the Clock/Trigger controller, that generates the clock towards prescaler and the timer. The counter is incremented or decremented according to number of pulses, the direction goes directly from the calculated angular change.

I guess, that prescaler > 0 will introduce wrong no. of pulses, if the direction changes during the measurement, because it doesn't reflect the DIR signal... Is it your case, can you confirm?

Btw. the encoder input freq. is sampled synchronously with TIMx_CLK signal, so it must be < TIMx_CLK/2.

muralisridhar
Associate II
Posted on May 17, 2011 at 13:24

hello,

I am using timer4 for encoder interfacing with STM32f103vet6. PB6

is timer4_channel_1 and PB7 is timer4_channel_2.

iam using encoder which has 200 pulses per revolution.

here iam using encoder mode 3. here is my configuration.

� CC1S=’01’ (TIMx_CCMR1 register, IC1FP1 mapped on TI1).

� CC2S=’01’ (TIMx_CCMR2 register, IC2FP2 mapped on TI2).

� CC1P=’0’ (TIMx_CCER register, IC1FP1 non-inverted, IC1FP1=TI1).

� CC2P=’0’ (TIMx_CCER register, IC2FP2 non-inverted, IC2FP2=TI2).

� SMS=’011’ (TIMx_SMCR register, both inputs are active on both rising and falling

edges).

� CEN=’1’ (TIMx_CR1 register, Counter is enabled).

since iam using encoder interface controller should take external signal as clock.

but when iam configuring timer4 clock for 18 mhz by setting prescaler 1.

counter is counting 200 ppr exactly. but when iam changing prescaler

counter is giving wrong values.

my question is what is relation between internal clock and encoder interface. here is the code.

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOB, &GPIO_InitStructure);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);

TIM_TimeBaseStructure.TIM_Period = 65535;

TIM_TimeBaseStructure.TIM_Prescaler = 0;

TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

TIM_PrescalerConfig(TIM4, 1, TIM_PSCReloadMode_Immediate);

TIM_EncoderInterfaceConfig(TIM4, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);

TIM_Cmd(TIM4, ENABLE);