Skip to main content
JGu.2
Visitor II
August 26, 2022
Question

Question of dac output frequency

  • August 26, 2022
  • 5 replies
  • 1649 views

Hi,

Recently I used STM32F407 to develop firmvare code of external DAC device.

In order to obtain a sinewave output from dac, I choose TIM2 to trigger interrupt.

TIM2_period is configured as 167, and TIM2_prescaler is configured as 0. The sysclk is 168MHz. The points in a period of sinewave are 300.

According to the configuration above, the frequency of sinewave should be 168M/168/300=3.3khz. But the actual frequecny is 551.8hz. It seems a huge difference between calculation and actual situation.

Could you give me an explanation about this phenomenon?

This topic has been closed for replies.

5 replies

gregstm
Senior II
August 26, 2022

Not sure. Things you could try - enable the MCO output (scaled down) to check the system clock frequency, enable the timer interrupt handler and pulse an IO pin in the handler to check the timer update frequency.

S.Ma
Principal
August 27, 2022

Use a timer to trigger next dac data out from dma in cyclic mode, no interrupt. The table size in this case covers a full period. Use a timer output compare pin and loop it back to the dac trigger pin during bringup. Once all good, use internal mcu signals to free these pins. The sinus period depends of timer pwm frequency and table size.

Michal Dudka
Lead
August 27, 2022

The most common problem is wrong clock configuration. Carefuly check what is your real sysclk frequency.

Tesla DeLorean
Guru
August 27, 2022

If​ you interrupt too frequently, the processor will saturate.

Code is either blocking, or taking longer than the interrupt periodicity. ​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Piranha
Principal III
August 27, 2022

Timers are not clocked from SYSCLK, but from their bus. As TIM2 is on APB1, it has a maximum frequency of 84 MHz. And, as Tesla said, one cannot have interrupts at a MHz rate. Set up a DMA and trigger it by a timer update event.