cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F334R8 reading ADC (single channel timer triggered) with 2us intervals

UKilc.1
Associate II

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.)

12 REPLIES 12
victagayun
Senior III

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

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.

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?