cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G071 : TIMER (TIM6) Immediate Update of Reload Value (ARR)

Karan 123
Senior

Hi,

I am using STM32G071RB MCU 64-PIN TQFP and using Timer TIM6.

The ARR Register in not updated Immediate and It updated on Next Transistion.

Please understand below situation .

1) I have set below in STMCube.

0693W00000QNyvvQAD.png2) As as Per calculation.0693W00000QNyxhQAD.png3) When I write ARR = 10 and after ARR = 90. .

a) The Timer first generate delay according 90.

b) Then according to ARR = 10.

I am Reload as below function.

void TimerReload(Reload Value)

{

 TIM6->PSC = 6350 ;

 TIM6->ARR = ReloadValue ;

 HAL_TIM_Base_Start_IT(&htim6) ;

}

Is my Timer reloading method is correct or not ?

Anybody please reply..

Thanks in advance..

--

Karan

1 ACCEPTED SOLUTION

Accepted Solutions

Clock in RCC has to be enabled as the very first thing.​

​Also read http://www.efton.sk/STM32/gotcha/g42.html

JW​

View solution in original post

6 REPLIES 6

0693W00000QNyrPQAT.pngJW

Karan 123
Senior

Hi @Community member​ 

Thanks for update.. Please check my edited Post #1 and reply if possible.

--

Karan

I don't use Cube. Who knows what those functions do now, and what will they do in the next version of Cube.

Timers are simple, read the TIM chapter in manual and use registers.

Preload of TIMx_ARR is controlled by TIMx_CR1.ARPE, but note, that TIMx_PSC is unconditionally preloaded, if you want to get it active immediately you have to force an Update event, usually by setting TIMx_EGR.UG.

Most of the time you want the preload to be active.

JW

Hi,

Thanks Again for Update.

#define TIM_CR1_ARPE_Pos     (7U)

#define TIM_CR1_ARPE_Msk     (0x1UL << TIM_CR1_ARPE_Pos)         /*!< 0x00000080 */

#define TIM_CR1_ARPE       TIM_CR1_ARPE_Msk               /*!<Auto-reload preload enable

#define TIM_EGR_UG_Pos      (0U)

#define TIM_EGR_UG_Msk      (0x1UL << TIM_EGR_UG_Pos)          /*!< 0x00000001 */

#define TIM_EGR_UG         TIM_EGR_UG_Msk                /*!<Update Generation */

Do you mean like this ?

void TimerReload(Reload Value)

{

 TIM6->PSC = 6350 ;

TIM6->CR1 |= TIM_CR1_ARPE ;

TIM6->ARR = ReloadValue ;

TIM6->EGR |= TIM_EGR_UG  ;

 HAL_TIM_Base_Start_IT(&htim6) ;

}

Or Anything..I am doing something wrong.

--

Karan

Hi @waclawek.jan (Community Member)​ 

Is this is right way to update Timer Register Immdiatley without STMCubeCode ?

void TimerReload(unsigned int Reload Value)

  TIM6->CR1 &= ~(TIM_CR1_CEN);          // Disable the Counting First

  RCC->APBENR1 |= (1u << 4 );       // ENABLE TIM6 CLOCK

  

  TIM6->PSC = 6350 ;                       // Set Prescaler

 TIM6->CR1 |= TIM_CR1_ARPE ;          // Auto-reload preload enable

 TIM6->ARR = ReloadValue ;                  // Auto-reload register

 TIM6->CNT = 0 ;                                   // Counter register

 TIM6->EGR |= TIM_EGR_UG  ;             // Update Event Generation

 TIM6->DIER |= TIM_DIER_UIE;              // Enable the Update Interrupt

 TIM6->CR1 |= TIM_CR1_CEN;               // Enable the Counting

}

Thanks In Advance..

--

Karan

Clock in RCC has to be enabled as the very first thing.​

​Also read http://www.efton.sk/STM32/gotcha/g42.html

JW​