cancel
Showing results for 
Search instead for 
Did you mean: 

When TIM4 is set to encoder mode, what is the minimum pulse width it can capture

DChan.2
Associate II

I use to stm32f302 to measure the external encoder signal. There is no problem at low speed, but it will not work when the pulse width is reduced to about 11us. I want to know what is the limit pulse width (minimum) when TIM is set to encoder mode.

Pulse width as shown:0693W000001pP5lQAE.png

The initialization code is as:

void encoder_pin_init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB, ENABLE);
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_6;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;	
	GPIO_Init( GPIOB, &GPIO_InitStructure );	
	
	GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_2);
	GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_2);	
}
 
void encoder_timer_init(void)
{
	TIM_TimeBaseInitTypeDef  	TIM_TimeBaseStructure;
/* 	TIM_ICInitTypeDef 				TIM_ICInitStructure;
 */
	RCC_APB1PeriphClockCmd(	RCC_APB1Periph_TIM4, ENABLE );
	TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); 
 
	TIM_DeInit(TIM4);
	TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);		
	    
	TIM_TimeBaseStructure.TIM_Period =0xffffu;
	TIM_TimeBaseStructure.TIM_Prescaler =0u; 
	TIM_TimeBaseStructure.TIM_ClockDivision = 0u;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;     
	TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);	    	
	
	TIM_EncoderInterfaceConfig( TIM4, 
								TIM_EncoderMode_TI1,
								TIM_ICPolarity_Rising, 
								TIM_ICPolarity_Rising );
	
/* 	TIM_ICStructInit(&TIM_ICInitStructure);
	TIM_ICInitStructure.TIM_ICFilter = 6;
	TIM_ICInit(TIM4, &TIM_ICInitStructure);
	
	TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
	TIM_ICInit(TIM4, &TIM_ICInitStructure); */
 
	TIM_Cmd(TIM4, ENABLE); 	
}

21 REPLIES 21
Laurent Ca...
Lead II

Dear @Community member​ 

I am in charge of improving the dynamism of the "STM32 Motor control" tag community.

For such specific question do not hesitate to open a specific post with only the tag "STM32F3".

Best regards

Laurent Ca...

Hi @Laurent Ca...​ ,

This is not a 'F3-specific question, bot goes across the entire STM32 family; and in fact does relate to motor controls, too.

JW