Sidenote: You may have seen my earlier question. This is a repost I guess but I've done a lot more work trying to analyze the problem. I thought it warranted asking a new question. Sorry if it doesn't :/

So I have a TI TM4C123GXL microcontroller. I'm trying to produce sound using the GPIO pins and a 10bit DAC I made from a resistor ladder.

The Circuit:

Here's what the hardware looks like: http://i.imgur.com/upVLToV.jpg

So my microcontroller is connected to the DAC with the GPIO pins. The board puts a voltage of 3.3V on the pins for a logic high. The DAC output is connected to a small 3.5mm jack component where you can plug in headphones or a speaker w/ an aux cable.

The DAC is an R-2R resistor ladder with the R being a 10k resistor and the 2R being a 20k resistor. They both have tolerances of 1% each. I also have a 0.1 uF capacitor in parallel with the DAC output to smooth out the curves a bit.

I did a ramp up test and a sine wave test with an oscilliscope and the curves came out quite nicely:

PROBLEM 1: Unfortunately when I plug headphones into the jack, the voltage output is choked and the curve becomes super noisy (notice the voltages marked by the cursors):

The Code:

To produce sound I take an array that is essentially a lookup table for a single period of a sine wave. For this project I'm using an array with 1024 values, ranging from 0 to 1023. Using a timer, I send a value from the array to the DAC using a cursor that scrolls through the waveform. The faster the cursor scrolls (i.e. the lower the reload value of the timer), the higher the frequency and the higher the pitch produced.

Using two timers, I scroll through the lookup table with 2 independent cursors. I then add the values using the the formula A + B - AB/1024 and send this value to the DAC. In theory this should send a mixed signal to the DAC that sounds like a chord.

PROBLEM 2: Unfortunately I get a horrible distortion sound: https://soundcloud.com/rutvik-choudhary/dac-output-test-1

Mathematically this is what I expect to see: http://i.imgur.com/im5bXqU.png

In reality, this is what I get:

Could anyone point me in the right direction as to what exactly my problem is? I'm not really sure what could be causing this problem...

  • \$\begingroup\$ "I then add the values using the the formula A + B - AB/1024" - if you are just adding them, why multiply a x b? What is the impedance of your headphones? \$\endgroup\$ – Bruce Abbott Nov 30 '16 at 6:40
  • \$\begingroup\$ @BruceAbbott I was using the technique described here: vttoth.com/CMS/technical-notes/68-mixing-digital-audio. Not sure what the impedence of my headphones is, how should I measure it? Can I use a ohmmeter? \$\endgroup\$ – rcplusplus Nov 30 '16 at 7:05
  • \$\begingroup\$ Try drawing a schematic. \$\endgroup\$ – Andy aka Nov 30 '16 at 13:12
  • \$\begingroup\$ Schematic of what? \$\endgroup\$ – rcplusplus Nov 30 '16 at 17:12
  • \$\begingroup\$ Schematic of the complete circuit. From DAC to audio jack \$\endgroup\$ – user3219492 Dec 2 '16 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.