cancel
Showing results for 
Search instead for 
Did you mean: 

Question of dac output frequency

JGu.2
Associate

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?

5 REPLIES 5
gregstm
Senior III

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

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.

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

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
Up vote any posts that you find helpful, it shows what's working..
Piranha
Chief II

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.