cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L476 TIM15, single timer interrupt for delay purpose (630uSec)

Riscy00_UPP
Associate III

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;
}

---------------------

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *tim_baseHandle)
{
if(tim_baseHandle->Instance==TIM15)
{
HAL_TIM_Base_Stop_IT(&htim15);
 
if ((tim15count==20)||(tim15count==21))
{
zInfoTimeDWT("Tick");
}
if (tim15count<=20)
{
tim15Array[tim15count] = DWT_Get_uSec();
}
tim15count++;
}
}
---------------------
I had to apply stop timer via HAL_TIM_Base_Stop_IT() before I can action something with 630uSec delay. This solution avoid repeating interrupt loop, where I only require start-delay-stop (with interrupt). 
 
I open for suggestion for better way to do this? if possible, without using HAL_TIM_Base_Stop_IT()
 
I don't think one-shot is an appropriate solution because I'm not generating one shot pulse output. 
 
Thanks
 
 
 
 

 

 

 

 

1 REPLY 1
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".