AnsweredAssumed Answered

Create a precision timer with HAL and interrupt

Question asked by Bandini.Matteo on Nov 20, 2015
Latest reply on Nov 23, 2015 by Clive One
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();
     
}

Outcomes