cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F405 TIM1's repetition counter

Jerry_
Associate

I have a question when I read the reference manual of STM32F405, and it says that "for odd values of RCR, if  the RCR was written before starting the counter, the UEV occurs on the overflow (which should be underflow  as I have seen in TIMx_RCR function description from STM32F103 to ST... - STMicroelectronics Community)

And the reference says that  any write to the TIMx_RCR register is not taken in account until the next repetition update event . So my question is in center aligned mode if it is the first time we write the RCR after starting the counter and when will the first UEV happened ?

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Jerry_ ,

The internal RCR counter has to count 0-3-2-1-0-3-2-1-0-3-.... (or it may be an upcounter 0-1-2-3-0-1-2-3... it's the same),  as its period is (RCR+1).

JW

View solution in original post

4 REPLIES 4
Sarra.S
ST Employee

Hello @Jerry_, welcome to ST Community 

As mentioned in the RM, In center-aligned mode, the UEV is generated on overflow or underflow event depending on when RCR was written.

Regarding your question (in case of writing to RCR after starting the timer), this is a step-by-step explanation: 

  1. Starting the Counter: When you start the timer, the counter begins from zero.
  2. Writing to TIMx_RCR: If you write to TIMx_RCR after starting the counter, this value will not be used until after the first update event.
  3. First Counting Cycle: The counter will count up to ARR and then back down to zero. The first UEV will occur at the end of this cycle (when the counter reaches zero: underflow).
  4. Applying TIMx_RCR Value: After the first update event, the RCR value that was written will be taken into account.

From this point on, the counter will generate a UEV after the number of up/down cycles set by the RCR value.

Please note that  If the RCR was written before starting the counter, the UEV occurs on the overflow(when it reaches ARR)

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.

[EDIT] I've just dug out an old thread where I analyzed this question and posted it here... just to realize it's the same thread you've posted in the initial post.

Isn't the diagram I posted, and my whole dialogue there, clear enough?

As @Sarra.S wrote above, as RCR is preloaded, it's not taken into account until the first Update occurs after it's been written.

You can adopt the program I posted there to 'F4xx and experiment yourself.

JW

Hello @waclawek.jan ,in your diagram,1->∅ should generate an UEV , and the RCR in my opinion should be auto-reloaded to 3 , why it is reloaded to 3 the next overflow?

Jerry

0693W00000UFN67QAH.png

Hi @Jerry_ ,

The internal RCR counter has to count 0-3-2-1-0-3-2-1-0-3-.... (or it may be an upcounter 0-1-2-3-0-1-2-3... it's the same),  as its period is (RCR+1).

JW