cancel
Showing results for 
Search instead for 
Did you mean: 

Frequency precision when generating sine wave with DAC

JMSuckow
Associate

I am currently developing on a NUCLEO-G071RB board and I need to generate sine waves with frequencies in the range 1Hz - 11kHz. My project requires the step between the frequencies to be 1Hz. It doesn't have to be precisely 1Hz but it has to be close enough to differenciate 10000Hz from 10001Hz, for instance.

My current implementation has the following characteristics:

  • Using DAC channel 1 with DMA and 100 points (samples) to generate the sine signal format.
  • Using TIM6 as the trigger for the DAC. I am changing the timer prescale and the period configuration "on-the-fly" in order to achieve some frequencies.
  • Using the Internal Oscillator so that the SystemCoreClock is configured as 63MHz (could not get it to work with 64MHz for some reason).

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4;
  RCC_OscInitStruct.PLL.PLLN = 63;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV10;
  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV4;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV4;

By modifying the parameters of TIM6 I can reach close enough to the frequencies I need. My problem is that the higher the frequency is, higher it is the error on the precision.

Exemplifying: When I try to genereate a sine wave with frequency of 10.1kHz. The result (measure on the oscilloscope) varies from 10039Hz to 10164Hz. I have played with some of my settings but it didn't change much.

Some of this imprecision is caused by the internal oscillator. I haven't had the opportunity of trying with an external oscillator because there isn't one on the development board.

Is it possible to generate the signals I need (1Hz precision on the high frequencies) with the DAC on this microcontroller? I have already read AN4566, but I couldn't find anything in it about precision of the frequency generated.

Do you have another suggestion or approach on the matter? It can even involve some circuitry, if needed.

Thank you in advance!

2 REPLIES 2
RMcCa
Senior II

You could try dds. There are plenty of descriptions of the process on line. You will want to use a timer to interrupt the processor to update the dac at a constant rate. Use as high a sample rate as possible to avoid sin(x)/x errors. Also, i think an external crystal might help as well, the data sheet will tell you.

S.Ma
Principal

If the sine wave is made of 100 discrete values, the timer must run at 11000x100=11 MHz probably with a trigger pulse requires at least 2x this.

If the measured frequency varies (10039Hz to 10164Hz) in a matter of seconds and long after the chip warmed up, then it could be something else than the oscillator which tolerance would statically create errors.

Have you tried with more than 100 steps for the sine wave?