I generated Sine wave using Arduino Due on DAC0 pin with the help of a sine lookup table. I tried achieving a frequency of 50 Hz by setting the sampling time of samples as 166.6666667 microseconds. When checked the signal received on DAC output using Oscilloscope, the frequency is wiggling too much and it's not stable. But in my project, I need high precision. Such fluctuations will not serve the cause, how can I make DAC output stable? Please guide through it. Thanks in Advance.
I am also posting my code below: -
#include <DueTimer.h>
#include "Waveforms.h"
volatile int wave0 = 0;
int i = 0;
void myHandler_1()
{
analogWrite(DAC0, waveformsTable_1[wave0]*); *
i++;
if (i == maxSamplesNum)
- i = 0;*
}
void setup()
{
Serial.begin(9600);
analogWriteResolution(12);
NVIC_SetPriority(TC4_IRQn, 1);
Timer4.attachInterrupt(myHandler_1).start(166.6666667); // DAC
}
void loop()
{
}
Code in Waveforms.h header file
#ifndef Waveforms_h
#define Waveforms_h
#define maxWaveform 1
#define maxSamplesNum 120
static int waveformsTable_1[maxWaveform][maxSamplesNum] = {
{ - 2047, 2154, 2261, 2367, 2473, 2577, 2680, 2781, 2880, 2977,*
- 3071, 3162, 3250, 3336, 3417, 3495, 3569, 3638, 3703, 3764,*
- 3820, 3871, 3917, 3959, 3994, 4025, 4050, 4069, 4083, 4092,*
- 4095, 4092, 4083, 4069, 4050, 4025, 3994, 3959, 3917, 3871,*
- 3820, 3764, 3703, 3638, 3569, 3495, 3417, 3336, 3250, 3162,*
- 3071, 2977, 2880, 2781, 2680, 2577, 2473, 2367, 2261, 2154,*
- 2047, 1940, 1833, 1727, 1621, 1517, 1414, 1313, 1214, 1117,*
- 1023, 932, 844, 758, 677, 599, 525, 456, 391, 330,*
- 274, 223, 177, 135, 100, 69, 44, 25, 11, 2,*
- 0, 2, 11, 25, 44, 69, 100, 135, 177, 223,*
- 274, 330, 391, 456, 525, 599, 677, 758, 844, 932,*
- 1023, 1117, 1214, 1313, 1414, 1517, 1621, 1727, 1833, 1940*
},
};
#endif