2023-07-30 11:25 AM
I have written a code which test the TIM15 for delay response of 630uSec (using DWT to measure in uSec). Below is the working code (superloop). I have looked into oneshot and could not make it work from CubeMX and TIM15 configuration.
I found it was generating premature interrupt at the start, so I applied the fix by clearing the IT flag (__HAL_TIM_CLEAR_IT) assuming this is the right solution.
if (zsystickobj->zSysTick.zSystick_500mSec_Flag==1)
{
TIM15_UpdateDWT();
__HAL_TIM_CLEAR_IT(&htim15, TIM_IT_UPDATE); // Had to place this code to mitigate premature trigger!
HAL_TIM_Base_Start_IT(&htim15);
zsystickobj->zSysTick.zSystick_500mSec_Flag=0;
}
---------------------
2023-07-30 11:52 AM
Set the prescaler such that it ticks at 1 per us, set ARR=0xFFFF (which is the default), initialize it to CNT=0 and star the timer.
Then to check if delay is done, check if CNT >= 630.
No need for interrupts here.
To repeat, set CNT=0 again.
Lots of other ways to do it. Could also set ARR=629 and wait for the update flag to be set. I would use DWT personally or a 32-bit counter which you can just let overflow.