2023-05-03 08:32 AM
2023-05-04 03:05 AM - edited 2023-11-20 06:34 AM
__HAL_TIM_GetCounter(&htimX) allow to read CNT register where is the value that correspond with current "time". As time We mean nummber of clock cycles. When your CNT register equals ARR register, then CNT register reset and count again.
__HAL_TIM_GetCompare(&htimX, TIM_CHANNEL_X) allows read CCR register. The register used to for example in Output compare mode or input capture mode.
In Output compare mode (toggle mode):
You can manipulate signal when registers have been equal. When CNT == CCR then the signal toggles.
Remeber this is just example. CCR register support many various cases and features
2023-05-03 08:54 AM
And why don't you check the HAL reference?
I do not use HAl, but I would guess that the first returns the value of CCRx and the second - CNT.
2023-05-03 08:59 AM
I checked this UM1785 document which is "Description of STM32F0 HAL and low-layer drivers".
But not able to understand.
2023-05-04 03:05 AM - edited 2023-11-20 06:34 AM
__HAL_TIM_GetCounter(&htimX) allow to read CNT register where is the value that correspond with current "time". As time We mean nummber of clock cycles. When your CNT register equals ARR register, then CNT register reset and count again.
__HAL_TIM_GetCompare(&htimX, TIM_CHANNEL_X) allows read CCR register. The register used to for example in Output compare mode or input capture mode.
In Output compare mode (toggle mode):
You can manipulate signal when registers have been equal. When CNT == CCR then the signal toggles.
Remeber this is just example. CCR register support many various cases and features
2023-05-04 07:41 AM
Thanks Kamil
2023-05-04 08:12 AM
Do you understand the differences ?
2023-05-04 08:23 AM
I am trying to use one of the timers as a counter. So that it can read external clock pulses. What I understand from your explanation is that I have to use the following
__HAL_TIM_GetCompare(&htimX, TIM_CHANNEL_X
to check if the pulse at the input pin is high.
2023-05-04 10:28 AM
Read the Reference Manual regarding timer capture compares, then read a Timer Capture example included with the HAL Library.
A capture event (e.g, input pulse high) saves the contents of the Timer Counter, and this event can be sensed with a timer interrupt, so a separate and less accurate __HAL_TIM_GetCounter is not required.
2023-05-04 11:07 AM
If you want use timer as counter you don't need compare registers
2023-05-05 08:08 AM
Is this the document you are referring to PM0215 "STM32F0 series Cortex-M0 programming manual"