cancel
Showing results for 
Search instead for 
Did you mean: 

Counter using hrtim

Harsh_18
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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

 

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.

View solution in original post

7 REPLIES 7
ELABI.1
ST Employee

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_18
Associate II

Hi @ELABI.1,

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

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.

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.

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

 

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.

Thanks, and the last one is how we create the irq timer of 1us through hrtim

Here is the necessary configuration to create the 1µs IRQ timer using HRTIM:

ELABI1_0-1743078389298.png

ELABI1_1-1743078398417.png

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.