2022-08-26 01:47 AM
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?
2022-08-26 06:49 AM
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.
2022-08-26 08:10 PM
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.
2022-08-26 11:47 PM
The most common problem is wrong clock configuration. Carefuly check what is your real sysclk frequency.
2022-08-27 12:48 AM
If you interrupt too frequently, the processor will saturate.
Code is either blocking, or taking longer than the interrupt periodicity.
2022-08-27 06:26 AM
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.