cancel
Showing results for 
Search instead for 
Did you mean: 

Counter output compare

Hesseltjuuh
Associate III

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

5 REPLIES 5
AScha.3
Chief III

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

 

If you feel a post has answered your question, please click "Accept as Solution".
Hesseltjuuh
Associate III

Hey thanks for responding.

 

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

Hesseltjuuh_0-1703600557630.png

 

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

 

If you feel a post has answered your question, please click "Accept as Solution".
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".

Eventually just used TIM1, thanks anyway!