Skip to main content
Associate II
March 11, 2025
Solved

Counter using hrtim

  • March 11, 2025
  • 2 replies
  • 878 views

Hii, 

I am using hrtim in stm32G474RET6 mcu, so i want to know how we generate a counter of 500ns in which i call adc in it.

If somebody know about it please help me.

Best answer by ELABI.1

Hi @Harsh_18,

You can use a DMA request. The ADC is capable of generating this request to notify the DMA of the end of the conversion. The best way to use the DMA with the ADC is in continuous mode, with a DMA destination (a variable in memory), so that the user can use this variable without worrying about when it is updated by the ADC. When the ADC completes the conversion, it generates a request to the DMA, which copies it into this variable. Since continuous mode is enabled and the DMA is in circular mode, all the previous steps will restart automatically.

Here is the necessary configuration for this behavior:

ELABI1_0-1742996913511.pngELABI1_1-1742996923260.png

For starting the ADC with DMA and specifying the destination variable, you could use:  

if (HAL_ADC_Start_DMA(&hadc1, (uint32_t *) &VARIABLE_DESTINATION, 1) != HAL_OK)
  {
    /* ADC initiliazation Error */
    Error_Handler();
  }

Thank you.

ELABI.1

 

2 replies

ELABI.1
Technical Moderator
March 12, 2025

Hi @Harsh_18,

You can refer to the Application Note AN5305, specifically section "2.8 Configuring the high-resolution timer". Additionally, you can consult the HRTIMcookbook, which can help you.

Thank you.

ELABI.1

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Harsh_18Author
Associate II
March 18, 2025

Hi @ELABI.1,

I worked on hal driver, so can you please guide me.

ELABI.1
Technical Moderator
March 19, 2025

Hi @Harsh_18?,

To generate a 500 ns PWM, you need to program and activate a counter with: HAL_HRTIM_WaveformCounterStart_IT(&hhrtim1, HRTIM_TIMERID_TIMER_A); / HAL_HRTIM_WaveformOutputStart(&hhrtim1, HRTIM_OUTPUT_TA1) for example, and generate a trigger to the ADC by this Timer unit, you can program the trigger at the beginning of the period:

ELABI1_0-1742384107623.png

Then on ADC side, you need to bind this trigger to conversion source, so ADC will start working when triggered by hrtimer period: 

ELABI1_1-1742384262099.png

I hope that I was able to help you.

Thank you.

ELABI.1

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Harsh_18Author
Associate II
March 25, 2025

Hi @ELABI.1,

Firstly thank you soo much for helping me. Can you please give me some more favour i.e. is this adc work in dma mode .

Another is i want to execute same code less than 10us but my adc(with dma) consume too much time .So what i do for that.