W E L C O M E

Namaste and Welcome to the "Nuts About Electronics" Blog.

I am an electronics hobbyist based in India. Recently, I rediscovered my childhood passion in tinkering with electronic circuits. I created this blog to share some of my projects, as well as provide some useful information to other hobbyists in India, where many electronic components are hard to find.

Please note that the projects as well as code in this blog are provided "as is", with no guarantees. Working with electricity, electronic components, soldering irons, etc. requires safety precautions - please use your common sense.

Good luck with your projects, and above all, have FUN!

MV

Monday, August 3, 2009

Making a 12-bit Serial DAC



I recently built a 12-bit serial DAC, using a pair of 74HC595 shift registers and a R/2R ladder. I know that the entire circuit can be replaced with a single IC. But I did for 2 reasons (1) To learn about R/2R ladder DACs and (2) I could not find 12-bit DAC ICs here. The end result might be wobbly, but it sure is cheap! (Rs. 25 vs Rs. 300).


Note

Since posting this, I have found that this method is not particularly accurate. See for instance the post here.


The Circuit

The main components here are the pair of 74HC595 shift registers, the R/2R resistor ladder and the LM358 Op Amp.



The shift registers are used to shift out the serial 12-bit data. Since we are sending 12 bits, we can't use the built in shiftOut() method, and have to resort to some direct port manipulation code for the same. The shift registers are connected to the Arduino as shown in the schematic on the Arduino ShiftOut tutorial.

The R/2R ladder is the core of the DAC. I used a set of single 100 K Ohm 1% resistors. You can read details about the R/2R ladders here.

The LM358 is configured as a voltage follower, since it isolates the R/2R network with a high input impedance.

The power supply to the Op Amp is separate 9V battery. I tried powering it with just the 5V from the Arduino, but it does not operate very well at inputs close to the supply voltage.

The Code


/*
* ShiftOutTest
*
* MV (http://electro-nut.blogspot.com/)
*
* This tests a 2 x 74HC595 + R/2R Ladder 12-bit DAC
*
*/

// 74HC595 pins
int pin_SH_CP = 6;
int pin_ST_CP = 7;
int pin_DS = 5;

// values
int readings[] = {
0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200,
1300,1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300,
2400, 2500, 2600, 2700,
2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800,
3900, 4000, 4096};

int N = sizeof(readings)/sizeof(int);

void setup()
{
pinMode(pin_SH_CP, OUTPUT);
pinMode(pin_ST_CP, OUTPUT);
pinMode(pin_DS, OUTPUT);
}


void loop()
{
for(int i = 0; i < N; i++) {
// ST_CP low
digitalWrite(pin_ST_CP, LOW);

// shift 12 LSB-first bits of data to shift register
shiftOut12(readings[i]);

// ST_CP high
digitalWrite(pin_ST_CP, HIGH);

// change this delay to suit your reading needs
delay(1000);
}
}

// shift out 12 bits of data
void shiftOut12(int data)
{
for(int i = 0; i < 12; i++) {
// SH_CP low
//PORTD &= ~(1<<6);
digitalWrite(pin_SH_CP, LOW);
// DS
// is i-th bit of data high?
if(data & (1<<i)) {
PORTD |= (1<<5);
}
else {
PORTD &= ~(1<<5);
}
// SH_CP high
//PORTD |= (1<<6);
digitalWrite(pin_SH_CP, HIGH);
}
// SH_CP low
//PORTD &= ~(1<<6);
digitalWrite(pin_SH_CP, LOW);
}



Results

I took 42 readings using a multimeter (enlisted the help of my wonderful wife - thanks, dear!), and the response does look very linear:



In a real application, I'd definitely got for a serial DAC IC - but it was nice to discover that it can be done this way!

Acknowledgments

Thanks to the excellent Arduino Forum and its members for helpful posts and discussions.

References

1. The Arduino ShiftOut Tutorial

http://www.arduino.cc/en/Tutorial/ShiftOut

2. Practical Electronics for Inventors by Paul Scherz

3 comments:

Anonymous said...

Hey there !

I was thinking about doing the same thing, however, did you try to add potentiometer ? By adding ones, you could have a really high precision, couldn't you ?

I was also wondering, how fast can you switch the DAC ? Can it match the wav format 44.1kHz ?

Anyways you can get my contact id here(I hate spam, using this against bots)

N3Ar ^^

mehcaver said...

I have the same interest - adding true DAC capability to an Arduino system. I think you should know, however, that blogger.com is very unfriendly to folks who try to expand your graphics, or god knows what else. The first thing that happens is that Picasa tries to get you to sign up with them. If you cancel out, they send you to a Google log-in page. When you do, you are forced to join again. This kind of interference is unfriendly to the blogger and commenter alike.

Anonymous said...

Online Casino Site | LuckyClub Live
Online casino site with best promotions. ✓ Register for Free and win real money with us ✓ Join Now. ✓ Join luckyclub Today.‎Promotions · ‎How to Play · ‎Is it Legal