Hardware timer interrupt for multiple delays(STM32g4)
Hi,
I am using STM32G4 in my project. I need delays in my project multiple places. I am using hardware timer interrupt for delay.
I am using TIM1 configured with 50 usec delay.
HAL_TIM_Base_Start_IT(&htim1);
HAL_TIM_PWM_Start_IT(&htim2, TIM_CHANNEL_2);
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM2)
{
if( flag_50 usec==1){
//read adc;
flag_50 usec=0; }
if(flag_800usec==1){
//check switch high/low
flag_800 usec=0 }
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM1)
{
uint16_t varible=0;
flag_50 usec=1;
variable++;
//take one variable to increment timer
if(varible==16)
flag_800usec==1;
}
}
1.As mentioned I need different delays in my project. For every pwm pulse rising edge after 50 usec I need to adc value and then after 800 usec I need to check one switch high/low. It should be repeated process. I am planning to use same timer for delay.
2.Once 50 usec delay done I need to take one variable to increment it for every 50 usec if it reached 16 times means(16*50 usec=800 usec) then I will take flag_800 usec to high and I will check the same in main function.
3.For remaining delays like 3 sec,2 sec I am planning do the same.
Is it correct process. If not Please suggest some other process to do it.
Thanks
