Frequency precision when generating sine wave with DAC
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!
