cancel
Showing results for 
Search instead for 
Did you mean: 

Is the formula for the frequency of the sine wave generated by the D / A converter in the document from ST incorrect?

HWorl.1
Associate II

Hi,

I generate a sine wave on the DAC. To trigger the DAC, I use the TIM 2 timer, which is clocked on the APB1 (32 MHz) bus, then I reduce its frequency through the dividers PSC = 15 and ARR = 1. In this way, I obtain the frequency from the timer equal to: 32 MHz / 16/2 = 1 MHz .

Then, theoretically, according to the formula: fsine_wave = f_timer_trg / ns where ns = number of samples, the frequency of the sinusoidal waveform is equal to (100 samples): ffsine_wave = 1000000/100 = 10 kHz. However, by connecting to the DAC channel, the oscilloscope receives a sinusoid with the frequency f = 5 kHz. Could someone explain why this is happening? This formula shouldn't look like this: fsine_wave = f_timer_trg / 2 * ns? There is a link to the document (page 15): https://www.st.com/content/ccc/resource/technical/document/application_note/05/fb/41/91/39/02/4d/1e/CD00259245.pdf/files/CD00259245.pdf/jcr:content/translations/en.CD00259245.pdf

2 REPLIES 2

Are you sure it's clocking the system at 32 MHz and not 16 MHz? PLL? HSI?

Can you print out the AHB, APB1 and APB2 clock speeds so you can confirm what the system thinks it's configured at. Saves a lot of confusion and guessing.

What part are we talking about?

Something along the lines of..

 printf("\n\nCore=%d, %d MHz\n", SystemCoreClock, SystemCoreClock / 1000000);

 printf("APB1=%d\n", HAL_RCC_GetPCLK1Freq());

 printf("APB2=%d\n", HAL_RCC_GetPCLK2Freq());

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TDK
Guru

> Is the formula for the frequency of the sine wave generated by the D / A converter in the document from ST incorrect?

The formula is correct. Think about it objectively. A new sample goes to the DAC on every trigger, not every other trigger (barring some sort of underrun condition). There must be some other explanation for what you are seeing.

You could be saturating the DMA bus, but doesn't seem like you should be at those rates. Could try reducing the timer clock by a factor of 10 and try again (PSC=15, ARR=19).

If you feel a post has answered your question, please click "Accept as Solution".