I am not able to understand the difference between following two:
__HAL_TIM_GetCompare(&htimX, TIM_CHANNEL_X)
__HAL_TIM_GetCounter(&htimX)
I checked the datasheet for STM32F031K6T6 but not able to understand the difference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-03 8:32 AM
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-04 3:05 AM - edited ‎2023-11-20 6: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-03 8: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-03 8:59 AM
I checked this UM1785 document which is "Description of STM32F0 HAL and low-layer drivers".
But not able to understand.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-04 3:05 AM - edited ‎2023-11-20 6: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-04 7:41 AM
Thanks Kamil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-04 8:12 AM
Do you understand the differences ​?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-04 8: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-04 11:07 AM
If you want use timer as counter you don't need compare registers ​
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-05-05 8:08 AM
Is this the document you are referring to PM0215 "STM32F0 series Cortex-M0 programming manual"
