cancel
Showing results for 
Search instead for 
Did you mean: 

DAC with Timer

GKIM.4
Associate II

Hello!​

I am using b-l475e-iot01a1, and I am currently working on DAC using Timer and DMA.

DAC uses Ch1 of DAC1 and Timer uses TIM2.

The TRGO of TIM2 is Update Event, and the Trigger of DAC is using TIM2 Trigger Out Event.

Sine function values from 64 samples are exported to DAC, and you want to set the frequency of the sine function to 200 Hz.

To do this, you want to set the TIM2 to 12.8 KHz (200 X 64 Hz).

The current APB1 Timer Clock is 80 MHz.

Therefore, Prescaler set 125-1 and Counter Period set 250-1. (80000 KHz / (25 X 250) = 12.8 KHz)

However, the frequency of the DAC is not 200 Hz, but 205 Hz.

What's the problem?

12 REPLIES 12

Thank you.

I checked clock source.

My problem is that clock source is set ​to MSI.

And I solved my problem by changing clock source to HSI.

As a result, dac output frequency is 200.2 Hz.

And I need to check the application note you gave me and optimize the accuracy of the HSI.

Thank you.

I found my error.

​I selected clock source to MSI.

So. I changed clock source to HSI.

As a result, DAC output is 200.2 Hz.

You're welcome ! Enjoy with the STM32

Otherwise, it's more understandable, because the MSI is less precise than HSI.

Best regards,

Simon TALAS

Please select an answer as best answer to close the question 😉