2015-11-20 03:41 AM
Hi guys,
I'm using CubeMx with HAL STM32F051. I need to activate a one shot timer with interrupt.Something likr this:void StartTimer(unsigned short microSecond){ ... ...}volatile unsigned char TimerIsOver = 0; void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) { TimerIsOver = 1;}void main(void) { LedOff(); TimerIsOver = 0; StartTimer(20); while(!TimerIsOver); LedOn(); TimerIsOver = 0; HAL_Delay(50); LedOff(); StartTimer(340); while(!TimerIsOver); LedOn(); } #stm32-hal-tim2015-11-20 10:20 AM
Any question?
2015-11-20 01:33 PM
For micro-seconds, where you're going to idle in a loop, why not just have that timer free run, and delta the tick count from TIMx->CNT ?
2015-11-22 11:18 PM
Please could you write for me StartTimer function?
Thank you very much...2015-11-23 06:14 AM
Sorry, I'm not writing HAL examples.
A free running timer would be a matter of configuring the time base in a maximal count mode, in your case probably with a 1us (1MHz) prescaled clock. Read the count at the start of the loop, and delta it over the duration. Interrupting at 1 MHz is NOT viable, so software counters aren't a solution.