Daily Archives: 2/24/2011

Arduino + MCP4725 Breakout Board

Well, the other I2C based breakout board I got from Sparkfun was for a Microchip MCP4725 DAC. It’s a 12 bit device, and will eventually do duty controlling the voltage controlled oscillator in my beacon transmitter. For tonight though, I just wanted to make sure I could program it, so I soldered on some header pins, plugged it into a breadboard, and coded up a small, simple program to simply send values from a table holding appropriately scaled sine values as quickly as possible. Here’s the code:

[sourcecode lang=”C”]

#include <Wire.h>

void
setup()
{
Wire.begin() ;
}

#define MCP4725_DEVICE 96

int sintab[64] = {2147, 2347, 2545, 2737, 2922, 3100, 3267, 3422, 3564, 3692, 3803,
3898, 3975, 4033, 4072, 4092, 4092, 4072, 4033, 3975, 3898, 3803,
3692, 3564, 3422, 3267, 3100, 2922, 2737, 2545, 2347, 2147, 1947,
1747, 1549, 1357, 1172, 994, 827, 672, 530, 402, 291, 196, 119, 61,
22, 2, 2, 22, 61, 119, 196, 291, 402, 530, 672, 827, 994, 1172,
1357, 1549, 1747, 1947} ;

int sp = 0 ;

void
loop()
{
Wire.beginTransmission(MCP4725_DEVICE);
Wire.send(64); // cmd to update the DAC
Wire.send(sintab[sp] >> 4); // the 8 most significant bits…
Wire.send((sintab[sp] & 15) << 4); // the 4 least significant bits…
Wire.endTransmission();
sp = (sp + 1) & 63 ;
}
[/sourcecode]

And here’s the brief YouTube video showing it in operation:



DS32kHz 32.768kHz Temperature-Compensated Crystal Oscillator

In considering the long term accuracy of the RTC chip that I was playing around with, I did some additional thinking and reading. My understanding is the error comes from the accuracy of the crystal oscillator: the 32.768Khz timing crystal probably has an accuracy of 20ppm or even larger. My guess is that this is expressed in two kinds of instability: a long term bias, which conceivably could be trimmed using a trimming capacitor, and a thermal component, which could be solved by temperature control. But in digging around, it appears that Maxim makes there own temperature controlled crystal oscillator, that has errors down in the 2ppm per year over a temperature range of 0 to 40 degrees Centigrade. Pretty nifty. They come in DIP (but non-stocked @ digikey) and various SOIC/BGA packages, with costs that might average around $10, which seems a bit spendy, but worth considering.

DS32kHz 32.768kHz Temperature-Compensated Crystal Oscillator – Overview

Kenneth mentioned the DS3232 as a more accurate version of the DS1307: it appears to me that the specifications for it are identical to the specification for the DS32kHz TXCO. My guess is that it’s simply an integrated package, but I haven’t had the chance to look at the datasheet yet. It does appear to be cost effective: you can get them from digikey in quantity one for less than five dollars. Worth looking into.

Addendum: Kenneth could have plugged his own excellent page on his build of a DS3232 based clock. Very nice, and includes a supercapacitor backup circuit for the DS3232. As it happens, I picked up a couple of supercaps from sparkfun with this order: I might have to give this a try.