2022-04-04 02:05 AM
Hi, I'm trying to read ADC data with 2us periods using ADC interrupts on Nucleo F334R8. I'm triggering ADC with TRGO event of Timer 2. I'm toggling a pin whenever callback function is called to debug using an oscilloscope. However, I cannot observe 2us on the scope. Pin cannot be toggled below 10us. I tried DMA method and got the same result. What could I be doing wrong here?
(I'm a beginner on STM32 and using CubeMx.)
2022-04-22 01:25 AM
I did this experiment.
HAL_ADC_Start_IT(&hadc1);
HAL_TIM_Base_Start(&htim2);
void ADC1_2_IRQHandler(void)
{
/* USER CODE BEGIN ADC1_2_IRQn 0 */
GPIOC->BSRR = (1<<8); // Set
/* USER CODE END ADC1_2_IRQn 0 */
HAL_ADC_IRQHandler(&hadc1);
/* USER CODE BEGIN ADC1_2_IRQn 1 */
GPIOC->BRR = (1<<8); // Reset
/* USER CODE END ADC1_2_IRQn 1 */
}
The duration is already 3.4uS.
Ton = 3.4uS
Toff = 340nS
2022-04-22 04:41 AM
I cut some irrelevant parts of the code before uploading here to simplify. I start the timer of course (must have forgotten it). I figured IRQ handler creates the issue as I said. I edited it and measured interrupt duration which lasts 2us now. Not great but ok for my application.
2022-04-23 02:25 AM
I commented out HAL_ADC_IRQHandler function.
Basically what I'm doing inside ADC1_2_IRQHandler now is this;
Set a pin high with HAL_GPIO_WritePin, clear EOS and EOC flag, get ADC value with HAL_ADC_IGetValue and set that pin low with HAL_GPIO_WritePin.
Now getting 2us pin high duration.
Do you think it is OK, or am I missing something?