2022-08-18 03:36 AM
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.
2) As as Per calculation.3) 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
Solved! Go to Solution.
2022-08-18 06:34 PM
Clock in RCC has to be enabled as the very first thing.
Also read http://www.efton.sk/STM32/gotcha/g42.html
JW
2022-08-18 03:49 AM
JW
2022-08-18 04:19 AM
Hi @Community member
Thanks for update.. Please check my edited Post #1 and reply if possible.
--
Karan
2022-08-18 04:29 AM
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
2022-08-18 05:09 AM
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
2022-08-18 12:14 PM
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
2022-08-18 06:34 PM
Clock in RCC has to be enabled as the very first thing.
Also read http://www.efton.sk/STM32/gotcha/g42.html
JW