Question
Hall Sensor Interfacing Timer
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);
}
