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.
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):
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:
- No headphones: http://i.imgur.com/CJgjdih.png
- With headphones (note that the voltage is choked and the signal is noisy): http://i.imgur.com/xzRqeMI.png
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...