What is the difference between these two functions.
__HAL_TIM_SET_AUTORELOAD(&htim3,45);
__HAL_TIM_SET_COUNTER(&htim3,45);
For example, if ı want to chance the Counter Period on the fly. Which one should ı use. What are the differences
On
Counter is the value that goes up (or down) on every timer counter tick. Reload value is a fixed maximum value of counter. Kinda like the last number on a clock before numbers start over.
Example:
Reload value: 10
Counter will go: 3...2...1...0-Timer update event (interrupt)...10...9...8
Reload value: 3
Counter will go: 3...2...1...0-Timer update event (interrupt)....3...2...1
Counters can go up or down depending on specific timer and its config.
Here is a piece from STM32F746 Reference manual, page 653, TIM1/TIM8 section. Timer reload value is 36, after that update event happens, Update Interrupt Flag (UIF) is set, and the counter starts over.

CK_PSC is a clock prescaler. Timer counter is incremented only every prescalerth tick. In case of this example, prescaler is 1, which means the timer counter increments on every timer source clock tick.
On
The two functions you've mentioned are part of the STM32 HAL (Hardware Abstraction Layer) library, used for configuring timers on STM32 microcontrollers. They serve different purposes related to the operation of timers:
__HAL_TIM_SET_AUTORELOAD(&htim3,45); - This function sets the value of the Auto-Reload Register (ARR) for the specified timer, in this case, htim3. The ARR determines the maximum value the timer will count to before it resets to 0 (or to the value in the Counter Register if the direction is down) and potentially triggers an interrupt or an event if the update interrupt (UIE) is enabled. Changing the ARR allows you to adjust the period of the timer on the fly. For periodic events, this controls how often the timer overflow (or underflow) event occurs.
__HAL_TIM_SET_COUNTER(&htim3,45); - This function directly sets the current value of the Timer's Counter Register (CNT) for htim3. It essentially changes the starting point of the timer's count. This can be useful for resetting the timer count or synchronizing the timer with an external event without changing the timer's period. If you set the counter to a value close to the ARR, the timer will reach the ARR value quicker, thus the next overflow or update event will happen sooner.
If you want to change the period of the timer (i.e., how long it takes for the timer to overflow and start over), you should use __HAL_TIM_SET_AUTORELOAD(). This will change how long the timer counts before it resets and triggers an overflow event.
If you need to reset the current count of the timer or synchronize it to a specific value in its counting cycle without changing the overall period, you would use __HAL_TIM_SET_COUNTER().
For dynamically adjusting the timer's frequency or period during operation, adjusting the ARR value with __HAL_TIM_SET_AUTORELOAD() is the appropriate choice.
The autoreload value is the value that the counter will count up to (or down from) before it resets.
The counter is the current value of the timer as it counts up or down.
So if you have an upwards counting timer, the counter value will start at zero, and increment once per tick (according to how the clock and divider have been configured). After it reaches the reload value, it starts again at zero. (And you can trigger an interrupt on this event.)
For a downwards counting timer, the counter starts at the reload value, and counts down once per tick, until it gets to zero. Then it reloads with the reload value (and optionally triggers an interrupt).
So if you wanted to change the counter period, it is the reload value you would change.