Hardware timer interrupt Delay in STM32G4
I am working with STM32G4. I am generating 1Khz PWM from my Timer2 and TImer1 I am using for delay(I configured it for 50 usec delay with interrupt).
Both timer2 and timer1 working as expected.
1.For every pwm pulse start I need to read adc for 50 usec after pulse start and after 800 usec of pulse start I need to check the GPIO this is my logic.
Now for testing purpose at 50 usec I am setting the led and at 800 usec I am resetting the led. But this is not working as expected.
HAL_TIM_Base_Start_IT(&htim1);
HAL_TIM_PWM_Start_IT(&htim2, TIM_CHANNEL_2);
setPWM_DutyCycle(TIM_CHANNEL_2,50);
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) {
if (htim->Instance == TIM2) {
dcheck.flagon_50usec=1;
if(delay.flag_50 == 1){
// HAL_ADC_Start(&hadc2);
// HAL_ADC_PollForConversion(&hadc2, HAL_MAX_DELAY);
// adcValues[currentIndex] = HAL_ADC_GetValue(&hadc2);
HAL_GPIO_WritePin(GPIOA, user_led,GPIO_PIN_SET);
delay.flag_50 = 0;
dcheck.flagon_50usec=0;
dcheck.flagon_800usec=1;
}
if(delay.flag_800usec == 1){
HAL_GPIO_WritePin(GPIOA, user_led,GPIO_PIN_RESET);
delay.flag_800usec = 0;
dcheck.flagon_800usec=0;
}
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim == &htim1)
{
// delay.flag_50 = 1;
if(dcheck.flagon_50usec){
dcount.u_50_sec++;
if(dcount.u_50_sec==1){
delay.flag_50 = 1;
dcount.u_50_sec=0;
}
}
if (dcheck.flagon_800usec)
{
dcount.u_800_sec++;
if(dcount.u_800_sec==16){
delay.flag_800usec = 1;
dcount.u_800_sec=0;
}
}
}
}
I checked in the oscilloscope led is high for 1 msec(one pwm pulse) and led is off for 2 msec(2 pwm pulse) it is showing in the scope. Can any one suggest what mistake I am doing. I gave high priority to PWM.
Thanks
