Stm32f407vgtx TIM output compare mode
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-06-26 6:51 AM - last edited on ‎2025-07-01 5:59 AM by mƎALLEm
Hi
I am trying to achieve output compare mode in TIM1 in stm32f407vgtx board .
I am trying to generate a delay of one ms and running a timer clock at 1mhz after divide it with prescaler.
I have enabled upcounter,TIM_CCER_CC1E bit in CCER, TIM_EGR_CC1G bit and loaded CCR1 as 999(one ms) and ARR as 0xFFFF but my counter is exceeding the value and it is going upto 65535 which is the ARR value .
I have not configured OC1M[2:0]bit (capture/compare mode register 1 (TIMx_CCMR1)) as I am not toggling PA8 or any thing on that pin which is linked with TIM1_CH1.
I want when ever counter value matches CCR1 it generates interrupt and I am toggling led inside that IRQ handler.
Can you help me where I am wrong please.
B.R
Ashish
Solved! Go to Solution.
- Labels:
-
STM32F4 Series
-
TIM
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-07-01 5:58 AM - edited ‎2025-07-01 5:58 AM
Hi @Ash1,
>> but my counter is exceeding the value and it is going upto 65535 which is the ARR value
This is normal as TIM1 counter continues counting up to the value set in the ARR register, which in your case is 0xFFFF. The CCR1 value is only a reference for comparison.
You need to:
- Generate an interrupt on CCR1 match, enable CC1IE and configure OC1M = 000, CC1E = 0.
- You do not need to toggle the output pin for the interrupt to work.
- In your IRQ handler, clear the CC1IF flag and toggle your LED
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-07-01 5:58 AM - edited ‎2025-07-01 5:58 AM
Hi @Ash1,
>> but my counter is exceeding the value and it is going upto 65535 which is the ARR value
This is normal as TIM1 counter continues counting up to the value set in the ARR register, which in your case is 0xFFFF. The CCR1 value is only a reference for comparison.
You need to:
- Generate an interrupt on CCR1 match, enable CC1IE and configure OC1M = 000, CC1E = 0.
- You do not need to toggle the output pin for the interrupt to work.
- In your IRQ handler, clear the CC1IF flag and toggle your LED
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
