2019-12-21 09:14 AM
Hi, do HAL_TIM_Base_Stop will clear couter? When I next Start the timer will it count from 0 or will count from random number that it stopped? There is no Base_Clear as I know.
Thanks
Solved! Go to Solution.
2019-12-21 09:42 AM
If you want to be in control, use the hardware registers as described in the reference manual.
The timer functional description chapters have some very helpful and detailed diagrams on the effects of setting various control bits.
Basically, issuing
TIMx->CR1 |= TIM_CR1_CEN;
starts the counter from the actual value of the CNT register, and
TIMx->CR1 &= ~TIM_CR1_CEN;
freezes the value in CNT.
The register description says that CNT is a read-write register, so you can set it to 0 or any other value when you want that.
Unfortunately the HAL documentation lacks that level of detail, so if you want to see exactly what they are doing, you have to reverse-engineer the HAL functions, which might be a lot more effort than following the step-by-step instructions in the reference manual.
2019-12-21 09:21 AM
Don't know, you can inspect the source, and experiment
TIM2->CNT = 0
2019-12-21 09:42 AM
If you want to be in control, use the hardware registers as described in the reference manual.
The timer functional description chapters have some very helpful and detailed diagrams on the effects of setting various control bits.
Basically, issuing
TIMx->CR1 |= TIM_CR1_CEN;
starts the counter from the actual value of the CNT register, and
TIMx->CR1 &= ~TIM_CR1_CEN;
freezes the value in CNT.
The register description says that CNT is a read-write register, so you can set it to 0 or any other value when you want that.
Unfortunately the HAL documentation lacks that level of detail, so if you want to see exactly what they are doing, you have to reverse-engineer the HAL functions, which might be a lot more effort than following the step-by-step instructions in the reference manual.
2019-12-21 11:44 AM
I did:
HAL_TIM_Base_Start(&htim3);
HAL_Delay(1); // random
HAL_TIM_Base_Stop(&htim3);
uint16_t x= TIM3->CNT;
if (x==0)
{
Send_usb_ok(); // just send info its ok
}
And if I didnt make mistake in code, it clears the CNT register after Base_Stop.
Thanks !
Prescaler=0
Period=65536
Pulse=0