cancel
Showing results for 
Search instead for 
Did you mean: 

Time Base for Timer in Encoder Mode

blue_dolphin1987
Associate II
Posted on June 06, 2014 at 05:13

Hi ,

I came across the following codes .

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 0xffff;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* Configure the timer */
TIM_EncoderInterfaceConfig(TIM4, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
/* TIM4 counter enable */
TIM_Cmd(TIM4, ENABLE);

I couldnt find any reference to how the time base is used when set to encoder mode. Why is the peroid set to 65535 ? Thanks #timers #timer-encoder-qei #stm32f3
2 REPLIES 2
Posted on June 06, 2014 at 06:10

It provides for maximal length of a 16-bit counter. If it were convenient to count 10000 increments you could use 9999 and have a count range 0 .. 9999

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jpeacock2399
Associate II
Posted on June 06, 2014 at 15:50

Encoder mode uses an external clock, derived from the step and direction phases of an encoder.  A common way to use a rotary encoder is to set the period to full scale, so the counter is the position as clocked by the encoder, -0x7fff to + 0x7fff, with zero as the midpoint, which can be triggered from the rotary encoder index output for the calibration point.

I use two encoders, rotary angle at 16 bit (TIM4), and a linear actuator at 32 bit (TIM5).  For rotary angle the timer period is the encoder count, so that it wraps at zero (the index point).  The linear actuator is an absolute position from a calibration point, so the period is set for full scale.

  Jack Peacock