Skip to main content
Graduate
December 26, 2023
Solved

Counter output compare

  • December 26, 2023
  • 3 replies
  • 2459 views

Hello,

 

I've used TIM2 to count to 100000 every second. With this i hope to make a very accurate millisecond timer. I can see the counter succesfully going to 1s and then i reset it manually using the RTC interrupt.

Now i want to use an output compare with no output to trigger an interrupt. But i can't do it. Please someone help me.

 

 

Hesseltjuuh_0-1703597687561.png

Hesseltjuuh_2-1703597891823.pngHesseltjuuh_3-1703597905087.png

 

 

    This topic has been closed for replies.
    Best answer by AScha.3

    Sorry, ...so you cannot use TIM1 or 8 ? 

    If it has to be tim2 : check, it calls TIM2_IRQ at all ?

    + check flags:

    AScha3_0-1703603433315.png

     

    3 replies

    Super User
    December 26, 2023

    Hi,

    did you enable the compare INT  at all ?

    AScha3_1-1703599158171.png

    (here enabled ! )

    then you get it in xx_it.c

    AScha3_2-1703599270008.png

     

    Graduate
    December 26, 2023

    Hey thanks for responding.

     

    Yes i did, but for this advanced timer there is only a global interrupt.

    Hesseltjuuh_0-1703600557630.png

     

    AScha.3Answer
    Super User
    December 26, 2023

    Sorry, ...so you cannot use TIM1 or 8 ? 

    If it has to be tim2 : check, it calls TIM2_IRQ at all ?

    + check flags:

    AScha3_0-1703603433315.png

     

    Graduate
    December 28, 2023

    Eventually just used TIM1, thanks anyway!

    Super User
    December 26, 2023

    Best way to time accurately is to set a free-running 32-bit counter using period=0xFFFFFFFF and do your time calculations using a difference of current value vs starting value. No need to restart the timer every 1s. Doing so makes the math more difficult.

    If you're set on doing it this way, put your reset code in HAL_TIM_PeriodElapsedCallback which gets called on the update event, provided you have interrupts enabled.