cancel
Showing results for 
Search instead for 
Did you mean: 

Hall Sensor Interfacing Timer

Berkan
Associate

Hello everyone,

I'm trying to to use TIM2 as interfacing timer to capture 3 hall sensor inputs. I set the TIMx.CR2.TI1S bit to XOR combination and use OC2REF is sent to TIM1 through TRGO as exactly said in RM0008 Interfacing with Hall sensors section. But COM event is not triggered. I think I do something wrong with linking timers. The code is below. Can anyone help me please?

 

void interfacing_timer(void)
{
/*TIM2 AS INTERFACING TIMER 3 HALL SENSOR INPUT XORED*/
 
RCC->APB1ENR |= 0x0001; /*TIM2 CLOCK ENABLE*/
TIM2->ARR = 0xFFFF ;
TIM2->CCR2 = 0x7fff ;
TIM2->CR2 |= 0x00D0 ; /*TI1S, MMS--->OC2REF*/
TIM2->CCMR1 |= 0x7003; /*CC1S AS TRC , OC2 PWM MODE 1*/
TIM2->SMCR |= 0x00000044 ; /*TI1F_ED, RESET MODE*/
TIM2->CR1 |= 0x0001; /*counter enabled*/
 
}
 
void tim1_init(void)
{
RCC->APB2ENR = 0x0001 ; /*CLOCK ENABLE TIM1*/
TIM1->PSC = 160-1 ;
TIM1->ARR= 1000-1 ;
TIM1->CCR1 = 500-1 ;
TIM1->CCR2 = 300-1 ;
TIM1->CCR3 = 750-1 ;
TIM1->DIER |= COMIE;
TIM1->SMCR |= 0x00000010; /*ITR1--TIM2_TRGO SELECTED*/
TIM1->EGR |= EGR_COMG ;
TIM1->CR2 |= CCPC | CCUS ;
NVIC_EnableIRQ(TIM1_TRG_COM_TIM11_IRQn);
 
}
4 REPLIES 4
Sarra.S
ST Employee

Hello @Berkan

Verify that TIM1 TRGO signal is being generated by TIM2 and received by TIM1

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello @Sarra.S , 

I am little confused. Shouldn't I generate TRGO by TIM2 and used this trigger as TRGI for TIM1 ?

Thank you..

Sarra.S
ST Employee

Hello again @Berkan

To program  channel 1 in capture mode (tim_TRC selected), you need to write '01' to CC1S bits in CCMR1

Also, according to the RM, you need to program channel 2 in PWM 2 mode by writing '111' to OC2M bits and ‘00’ to  CC2S bits. 

SarraS_0-1698848699360.png

taking this into consideration, 

>>TIM2->CCMR1 |= 0x7003; /*CC1S AS TRC , OC2 PWM MODE 1*/

should be TIM2->CCMR1 |= 0x7001;

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

liaifat85
Senior II

Please make sure that you have configured all the necessary register bits correctly.

https://www.st.com/resource/en/datasheet/stm32f405rg.pdf