cancel
Showing results for 
Search instead for 
Did you mean: 

Timer 1 Hallsensor interface - No interrupt from external signal.

Tobe
Senior III

This is how i the GPIO for the timer:

// Hallsensors (Tim1 capture) my_GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2; my_GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; my_GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(GPIOC, &my_GPIO_InitStruct); GPIOC->AFR[0] |= ( GPIO_AFRL_AFSEL0_1 | // AF2 (all) GPIO_AFRL_AFSEL1_1 | GPIO_AFRL_AFSEL2_1);

This is the timer config:

void initTim1AndTim8Hall(){ __disable_irq(); __HAL_RCC_TIM1_CLK_ENABLE(); SET_BIT( TIM1->CR2, TIM_CR2_TI1S); // config all 3 hall signals (PC0-2) via XOR to timer 1 WRITE_REG(TIM1->ARR, 0xFFFF); // Max value (is reset by input signal) WRITE_REG(TIM1->PSC, TIM1_PRESC - 1); // Mind the 1 that is added in the uC ! WRITE_REG(TIM1->CCR2, 20); // Delay value for PWM change trigger WRITE_REG(TIM1->CCMR1, 0); // set zero SET_BIT( TIM1->CCMR1, TIM_CCMR1_CC1S_0); // channel is configured as input, tim_ic1 is mapped on tim_ti1 SET_BIT( TIM1->CCMR1, TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_0); // PWM mode 2 - In upcounting, channel 1 is inactive as long as TIMx_CNT<TIMx_CCR1 else active. //SET_BIT(TIM1->CCMR1, TIM_CCMR1_IC1F_0); // filter if needed SET_BIT( TIM1->CR2, TIM_CR2_MMS_2 | TIM_CR2_MMS_0); // tim_oc2refc signal is used as trigger output (tim_trgo2 -> itr1 for timer 8) SET_BIT( TIM1->DIER, TIM_DIER_CC1IE); // enable interrupt on hall signal (is XOR with 2 and 3 SET_BIT( TIM1->CR1, TIM_CR1_CEN); // enable counter timer 1 NVIC_EnableIRQ(TIM1_CC_IRQn); // enable interrupt // OC1M is preploaded // slave mod reset input bei tim_ti1f_ed // capture/compare channel 1 is configured in capture mode, capture signal is tim_trc // ****** Timer 8 ****** //SMCR // timer 1 trigger out comes in on itr0 which is set with 0x0 by default initTimer8PWM(); startTimer8(); __enable_irq(); SET_BIT(TIM1->EGR, TIM_EGR_CC1G); //force interrupt }
View more

 

The interrupt is called when invoking it via software (see last line above).

- The value of the CCR does not change.

- I have checked the IDR for the right signal

- When i activate CC2IE-CCIE4, the interrupt is called over and over without doing anything to the button.

 

1 ACCEPTED SOLUTION

Accepted Solutions
waclawek.jan
Super User

When in doubts, read out and check/post content of TIM and relevant GPIO registers.

You haven't enabled TIM1_CH1 in TIM1_CCER.

JW

View solution in original post

2 REPLIES 2
waclawek.jan
Super User

When in doubts, read out and check/post content of TIM and relevant GPIO registers.

You haven't enabled TIM1_CH1 in TIM1_CCER.

JW

I have to give you a big thank you. I guess it would have taken me at least and hour to catch this. It is NOT mentioned in the example about hallsensors. One would only know, if one have worked with the capture before., if one had RTFM. :beaming_face_with_smiling_eyes: