cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743 TIM2 input compare

Handzic.Dirk
Associate III
Posted on May 19, 2018 at 10:48

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

10 REPLIES 10
Posted on May 29, 2018 at 08:34

That is right Jan, normally I am never using the CubeMX generated code, but for this project I tried it for the first time to get the board running faster and in order to get the USB stack supplied by ST running. As soon as time permits I will clean out all HAL calls where it is possible.

About ARR the RM says so all my fault:

In upcounting mode, the counter counts from 0 to the auto-reload value (content of the

TIMx_ARR register), then restarts from 0 and generates a counter overflow event.

Dirk