Hi,
I enabled the ADC DMA inside the Timer2 interrupt, and Put '1' for a GPIO PIN, as follows:
void TIM2_IRQHandler(void)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, 1);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *) buffer, 100);
HAL_TIM_IRQHandler(&htim2);
}
Then inside the ADC interrupt, I wrote '0' for the GPIO PIN and disabled the ADC DMA.
void DMA2_Stream0_IRQHandler(void)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, 0);
HAL_ADC_Stop_DMA(&hadc1);
HAL_DMA_IRQHandler(&hdma_adc1);
}
An interrupts latency is around 3 to 4uS. I confirmed it by toggling a PIN inside the timer interrupt with no other code.
ADC DMA holds 100 samples which takes around 50uS. In this code the PIN value change is above any code, BUT why the ADC conversion values gets added to the generated pulse?
I mean after firing the Timer interrupt + 4uS, I should see a rising edge on the oscilloscope screen, but I see that rising edge after 50uS. The GPIO code is ABOVE ADC code.
I test this phase shift with another clean signal with the same frequency by an oscilloscope, then I realized this. The frequency of the ISR pulse is low and 100Hz.
That's important for me here is the beginning. because I want to make sure that the ADC conversion starts on-time, not too late.
it's weird, why?