cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f4 encoder interface mode

arunnmishra
Associate II
Posted on August 09, 2014 at 06:51

Hi there! 

I'm using my stm32f4 timer 5 in encoder interface mode. In reference manual it is written for CCxNP/CCxP pins that they should not written 11 (i.e. polarity of trigger on both edges) in encoder interface mode which inhabiting me from getting interrupt on all four edges of encoder. Is there any way to get all four interrupts of encoder signal in encoder interface mode. Below is my initialization code -

GPIOH->AFR[1] |= 0x00002200;//PinPH10,PH11 in alternate function mode tim5 ch1 and ch2 respectively 

RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;//Clock source for timer5 enabled

TIM5->ARR = 0xffff;//Auto relode value for timer5

TIM5->PSC = 0;

TIM5->CCMR1 |= TIM_CCMR1_CC1S_0|TIM_CCMR1_CC2S_0; //Timer5 ch1 & ch2as input capture

TIM5->CCMR1 &= ~TIM_CCMR1_CC1S_1|TIM_CCMR1_CC2S_1;

TIM5->DIER |= (TIM_DIER_CC1IE | TIM_DIER_CC2IE);//tim5 capture/compare ch1 and ch2 interrupt enable

TIM5->SMCR |= TIM_SMCR_SMS_0|TIM_SMCR_SMS_1;//tim5 counter counts on both edges

NVIC_EnableIRQ(TIM5_IRQn);//globally enable timer 5 interrupt

TIM5->CCER |= TIM_CCER_CC1E|TIM_CCER_CC2E; //capture/compare 1 and 2 enable

TIM5->CR1 |= TIM_CR1_CEN;

Thanks   

#stm32f4-encoder-interface
0 REPLIES 0