Skip to main content
GMate.2
Associate
May 6, 2023
Solved

Time delay when operating with DAC in STM32L4

  • May 6, 2023
  • 3 replies
  • 1817 views

Hi everyone!

I use 8 MHz external oscillator for my MCU. For TIM1 there is no prescaler in CUBE, so I expect this timer to tick with pure 8MHz frequency. And therefore I expect to see 0.125 us * 2 * 2 = 0.5 us period of signal. But actually I have 24 us period duration. What does slow down my DAC output? How can I achieve 0.5 us period for my pulse signal?

Thanks.
_legacyfs_online_stmicro_images_0693W00000bjWJcQAM.png
_legacyfs_online_stmicro_images_0693W00000bjWKGQA2.png
_legacyfs_online_stmicro_images_0693W00000bjWJhQAM.png

This topic has been closed for replies.
Best answer by waclawek.jan

fast_delay() alone takes a couple of instrucions = couple of cycles to call, and then return from it.

But, more importantly Cube/HAL functions are bloated, so HAL_DAC_SetValue may easily execute hundreds of instructions until it gets to write the value to DAC register and return.

JW

3 replies

waclawek.jan
waclawek.janBest answer
Super User
May 6, 2023

fast_delay() alone takes a couple of instrucions = couple of cycles to call, and then return from it.

But, more importantly Cube/HAL functions are bloated, so HAL_DAC_SetValue may easily execute hundreds of instructions until it gets to write the value to DAC register and return.

JW

GMate.2
GMate.2Author
Associate
May 7, 2023

Thank you for the explanation

AScha.3
Super User
May 7, 2023

try simple test : comment / leave away the fast_delay(); lines.

then you see the speed/delay of the HAL_Dac-set.. timing .

If you feel a post has answered your question, please click on " Best Answer ".