Arduino UNO audio output with R2R DAC

I'm trying to implement audio output using R2R 8bit DAC and Arduino UNO.

This is my hardware:

This is the sound i want to hear:

This is a wav file, 16Khz, mono, 8 bit pcm.

I used matlab to retrieve the binary data from the wav file, and then wrote this code:

http://csharppad.com/gist/0f39da965e31fc838c6de73ff50e5669

I connected the output to some speaker and what i hear is some strange sound..do you think i miss something in my hardware/software?

Thanks!

OP's Circuit

Part of the code

#include <avr/pgmspace.h>
int ledPins[8] = {0,1, 2, 3, 4, 5, 6, 7};
const byte sound[] PROGMEM = {128,

 128, 128, 128, 127, 128, 127, 128, 127, 128, 127, 128, 128};
int pin, i;

void setup() {
 for(pin=0; pin<=7; pin++)
 pinMode(ledPins[pin], OUTPUT);
}

void loop() {

 for (i=0; i<sizeof(sound); i++)
 {
 PORTD=sound[i];
 
 delay(0.0625);

 }
 delay(2000);
}

Why are you have delay(0.0625); delay function only accept integer number.

You can use delayMicroseconds() function if you need less than millisecond delay.

R2RDAC.ino (54.1 KB)

billhowl:
OP's Circuit

Part of the code

#include <avr/pgmspace.h>

int ledPins[8] = {0,1, 2, 3, 4, 5, 6, 7};
const byte sound[] PROGMEM = {128,

128, 128, 128, 127, 128, 127, 128, 127, 128, 127, 128, 128};
int pin, i;

void setup() {
for(pin=0; pin<=7; pin++)
pinMode(ledPins[pin], OUTPUT);
}

void loop() {

for (i=0; i<sizeof(sound); i++)
{
PORTD=sound[i];

delay(0.0625);

}
delay(2000);
}





Why are you have delay(0.0625); delay function only accept integer number.

You can use delayMicroseconds() function if you need less than millisecond delay.

Ok i didn't know it... I will check it with delay microsecond.

Does the LM358's input common mode range include ground?
That's the only thing I can see that might be an issue- might need to ac couple the ladder to the amp and add a voltage div.
Mark S.

markba633csi:
Does the LM358's input common mode range include ground?
That's the only thing I can see that might be an issue- might need to ac couple the ladder to the amp and add a voltage div.
Mark S.

Ok now i hear something that close to the sound in the rate of it but it still a kind of noise/humming and not something close to voice...

I also noticed that if i remove the 220uf cap, 10nf cap and 10k resistor there is no difference in the sound i get..maybe the problem is in the op amp?