I wired up two MCP4725 DAC's to my Arduino and wrote a little demo sketch to test functionality. The sketch draws a Lissajous curve on my oscilloscope. The output frequency is a bit disappointing (approx. 1.5kHz sample rate), but the datasheet to the DAC mentions High Speed I2C mode. Does Arduino (Mega1280) support High Speed I2C mode and if 'yes' how?
#include <Wire.h>
#include <math.h>
#define DAC0 ( 0xCC >> 1 )
#define DAC1 ( 0xCE >> 1 )
int sh[ 360 ] , sl[ 360 ];
int ch[ 360 ] , cl[ 360 ];
void setup() {
Wire.begin();
for ( int a = 0; a <= 360; a++ ) {
int s = sin( a * 3.141592 / 180 ) * 2047 + 2048;
int c = cos( a * 3.141592 / 180 ) * 2047 + 2048;
sh[ a ] = int( s / 256 );
sl[ a ] = s - sh[ a ] * 256;
ch[ a ] = int( c / 256 );
cl[ a ] = c - sh[ a ] * 256;
}
}
void loop() {
for ( int b = 0; b < 360; b++ ) {
for ( int a = 0; a < 360; a += 6 ) {
Wire.beginTransmission( DAC0 );
Wire.send( ch[ a ] );
Wire.send( cl[ a ] );
Wire.endTransmission();
Wire.beginTransmission( DAC1 );
Wire.send( sh[ ( a * 2 + b ) % 360 ] );
Wire.send( sl[ ( a * 2 + b ) % 360 ] );
Wire.endTransmission();
}
}
}