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:
Hi Mark, Thanks for the interesting video on the I2C DAC. By a strange co-incidence I worked with Hans, G0XAR, on the first two generations of his beacon kits. Now I am working on some micro controller projects for beginners which I hope to publish later. My MCP4725 boards arrived today and as I have a bad cold I’ll be playing with them this evening rather than celebrating the new year.
73 from cold, cold England, Steve
hi this is my humble request how to send a serial data to dac.
am work this and get some output, the problem is only a single data is transmit after that the master to stop the operation.
how am sending continuously in real time please help me am attach my code here
#include
#include
#define disk1 0xc0>>1 //Address of 24aa32a eeprom chip
//#define sda A4
//#define scl A5
char incomingByte;
unsigned int integerValue=4000;
void writeEEPROM(int deviceaddress, unsigned int eeaddress,unsigned int data )
{
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write((int)(data >> 8)); // MSB
Wire.write((int)(data & 0xFF));
Wire.endTransmission();
}
void setup(void)
{
unsigned int address = 0;
Serial.begin(9600);
Wire.begin();
}
void loop(){
unsigned int address = 0;
if (Serial.available()) {
integerValue = 0;
while(1) {
incomingByte = Serial.read(); // char
if (incomingByte == ‘\ ‘) break;
if (incomingByte == -1) continue;
integerValue *= 10; // shift left 1 decimal place
// convert ASCII to integer, add, and shift left 1 decimal place
integerValue = ((incomingByte – 48) + integerValue);
}
}
Serial.println(integerValue); // Do something with the value
delay(500);
writeEEPROM(disk1, address, integerValue);
}
OUTPUT: DIGITAL VAL=4000, MY VOLT =4.8V THE I2C IS WORKING FOLLOWING MANOR: S C0 A 00 A 00 A F0 A 11 A P
THIS CODE IS USED TO DAC. THIS WORKING PREFECT IN ONE TIME. MY AIM THE DIGITAL VALUE IS PROVIDE BY USING SERIAL SO I NEED WRITE DATA CONTINUES PLEASE ANY ONE HELP ME.
I WILL TRY ANOTHER METHOD BY REPLACING THE LINE IN ABOVE CODE, THIS SEND DATA CONTINUES BUT IN THE DAC OUTPUT VOLTAGE NOT GET THIS MY PROBLEM.
THE CHANGES IS :Wire.endTransmission(false);
the output is:S SR C0 A 00 A 00 A F0 A 11 A SR C0 A 00 A 00 A F0 A 11 A ……. TO FOLLOW THIS MANOR. PLEASE HELP ME AM WAIT U R REPLY THANK YOU