Direct Input Capture Interrupt too slow - STM32 L476RG
I'm trying to align an input 15 kHz signal with a 20% duty cycle with an output 15 kHz signal with a 50% duty cycle. To do this I'm hooking up the input signal to a direct capture interrupt and Timer 1 Channel 4 and using the HAL_TIM_IC_CaptureCallback function to begin my PWM timer. In doing this I notice a significant delay of 6ms as shown in the picture below. I need the delay to be on the order of 1-2µs not 6ms. Is this possible using the STM32 L476RG operating at 80 MHz? Otherwise, what are some common solutions to meeting these kinds of timing requirements?
Here is my ISR for reference:
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4) {
if (num_pulses == 0) {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, state);
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
++num_pulses;
}
else if (num_pulses == 50) {
if (state = 0) {
state = 1;
}
else {
state = 0;
}
num_pulses = 0;
}
else {
++num_pulses;
}
}
}Here is the delay on the logic analyzer:
Thank you!
