cancel
Showing results for 
Search instead for 
Did you mean: 

I wonder if it is possible to use the DAC in STM32G4 to produce a 30kHz sinewave with 1Hz resolution.

GGold.3
Associate II

The application is to fine tune acoustic resonantors. In other words we want to be able to tune DMA DAC output from 29.990 to 30.010 in 1 Hz steps. Ideally we also would like to tune the amplitude. There are some ideas with DAC reference prescalers and different LUTs. Any idea for a more elegant solution?

11 REPLIES 11

That's what you get with DDS, too - you just change the phase *increment* value, so phase remains continuous.

JW

AScha.3
Chief III

well, question is: do you want/need full sinewave with many samples in constant pattern ?

then, as ...Jan and others explained, not possible.

if you can be ok with an little "noisy" pattern, then DDS is the solution.

because 32bit cpu here, lets take a 32bit dds -> and for good THD, 1024 elements 12 bit (data) value lookup table.

so we calculate a 32bit "phase-accu" , using top 10bits for the lookup table.

and we try calculation at 600kHz , = "sampling frequ." . (if we (cpu) can faster...good. we will see..)

the loop is simple:

// preset array with 1024 sinus values, one full 2pi wave
uint16_t sinval[1024];
 
uint32_t  phase_sum, phase_speed;
phase_speed = 213909504;  // for 29,882 KHz at 600k sampling
while(1 ...loop) // - or better : do in timer INT , called at 600kHz
{
  phase_sum += phase_speed;   // sum just rolls over...for next sine wave :)
  DAC1->DHR12R1 = sinval[phase_sum>>22];  // DAC1->DHR12R1 = mod. -> dac write register
}
 

so resolution is about 0,00011 Hz . (average....and need low pass filter, maybe 40kHz , 12dB/Oct. )

"program" is just to show the way, not without possible error...

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