AnsweredAssumed Answered

STM32H743 TIM2 input compare

Question asked by handzic.dirk on May 19, 2018
Latest reply on May 29, 2018 by handzic.dirk

Hi,

I can not get the input compare mode working as expected. I need to use TIM2 CH1 as trigger to measure the frequency of external pulses. I have used the methode on a STM32F091 where it works fine.

 

RCC and GPIO are initialized. And I will get a CC1IF interrupt as soon as I connect the external signal source BUT CCR1 is always 0! It seems to me the counter is not counting. My code to set up the counter:

 

#define VEL_CLK 10000000       //System is running at 200 MHz PSC is set to 4

 

TIM2->CCMR1 =  TIM_CCMR1_CC1S_0 ;                                     // ch 1  for input capture   
TIM2->SMCR =      TIM_SMCR_ETP |  TIM_SMCR_SMS_2 |
                                TIM_SMCR_TS_2;                                             // reset mode on ch1

 

TIM2->CCER = TIM_CCER_CC1P | TIM_CCER_CC1E;

 

 TIM2->PSC = (APB1_CLK / (VEL_CLK)) - 1;                             // Timer clock
          
 TIM2->CR1 = TIM_CR1_CEN;                                            // Start timer
          
 TIM2->DIER = TIM_DIER_CC1IE;
          
  NVIC_SetPriority(TIM2_IRQn,0);
  NVIC_EnableIRQ(TIM2_IRQn);

 

The TIM2 registers after intialization (see attached file).

 

Any suggestions very appreciated!

 

Best regards

Dirk

Attachments

Outcomes