SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions about carrier boards have here!
User avatar
By Mobiuss
The DAC works fine on an Arduino Uno with sample sketch to produce a sine wave, but I wanted to change the frequency. The only way I have found to do this is to use the setClock function, however it can give odd results:
between 30500 (1.519Hz) and 700000 (18.83Hz) it changes the frequency in a fairly linear way, but below 30500 it is inconsistent and at 30200 it goes completely mad.
Is there a better way to change the frequency of the sine curve in the "MCP4725 Digital to Analog Converter Hookup Guide" sample sketch?
User avatar
By liaifat85
Look for the part of the code that generates the waveform and adjust it to produce the desired frequency. Typically, this involves changing the increment of the angle in the sine function to modify the frequency.
User avatar
By Mobiuss
Hi, thanks for your reply.
The Sparkfun sample sketch for the DAC has an array of 512 points, y values only, no time or angle values, so is completely dependent on the speed of the Wire.write command. That's why changing the clock speed also changes the frequency. Because the write command takes a finite amount of time. Presumably an array with fewer points would give a higher frequency, but also a more notchy sine wave. I have used a formula to calculate the sine values but I think the lookup table is faster.
 Topic permissions

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum