cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32f407vgtx TIM output compare mode

Ash1
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions
Sarra.S
ST Employee

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.

View solution in original post

1 REPLY 1
Sarra.S
ST Employee

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.