I followed the tutorial here
exactly and the code is provided below but the audio output from speaker is like cracking sound white noise only. I have used BD135 as the second transistor and used 4.7k and 2.2k ohm resistors for the R-2R DAC.
The circuit and sound produced is as shown the video below.
I can not see which wire from the arduino goes to which resistor of the R-2R ladder.
So maybe it´s correct, maybe not.
The amplifier is really bad. It causes DC to go to the speaker. Usually the speaker can´t handle this, in worst case it´s coil burns.
It causes extremely high distortion because everything below 1.3V ladder ouput is ingored...this is almost 1/3 of the total signal range.
Every tiny audio amplifier will be better. You will also see the DC suppression (capacitor) in the signal path.
The speaker itself is in no good condition. Are you sure it´s working properly?
Wiring photo is not enough clear to see the position of BD135.. ( front or back)
Chek if you don't reverse the BD135 NPN SOT32
pin 1 base
pin 3 emitter
pin2 in the midle = collector
hi,
- the R-2R ladder should be good because i previously output sine wave through it and the wiring is good
- i noticed about the dc into speaker and i first tried using the capacitor but this did not work and from the video tutorial he got the audio from the speaker so i wanted to try it out
- i think i got high distortion but don't know how to solve
- i tried amplifier(LM358) with capacitor in signal path but audio output is same
- the speaker though looks bad is good, i got audio output using PCM method and playing music directly
any hints on what i can try? is the audio sample code good?
Wiring photo is not enough clear to see the position of BD135.. ( front or back)
Chek if you don't reverse the BD135 NPN SOT32
pin 1 base
pin 3 emitter
pin2 in the midle = collector
Output at the join of R14 R15 ranges from 0 to 5V. Try connecting it directly to one speaker terminal, and the other speaker terminal to 2.5 V. This provides proper AC to the speaker at a safe level. The purpose is to hear sound directly without sending it through an amplifier.
Current shall only be a couple mA. If volume is too soft then try reducing all ohm values in your R2R network.
The DAC isn't the real problem here. Given the correct digital output it will produce a good analog output.
The amplifier is where the problem lies. It has no voltage gain and needs at least 1.2V of signal from the DAC resistors before it even starts to pass current through the loudspeaker. Even then, the lower volume levels will be distorted because the amplifier can't run in class A mode.
The 'dirty' fix is to add a resistor from the base to collector of Q1 so it is forced to conduct some current all the time. That would fix the distortion but be very inefficient.
The simplest 'good' fix is to forget Q1 and Q2 altogether (they will NEVER work as a quality amplifier) and connect the junction of R14 and R15 through a capacitor (100nF will do) to a LM386 or similar amplifier. That gives you a lot more volume for a lot less current and,withing the limitations of the LM386, much higher quality sound.
Output at the join of R14 R15 ranges from 0 to 5V. Try connecting it directly to one speaker terminal, and the other speaker terminal to 2.5 V. This provides proper AC to the speaker at a safe level. The purpose is to hear sound directly without sending it through an amplifier.
Current shall only be a couple mA. If volume is too soft then try reducing all ohm values in your R2R network.
The DAC isn't the real problem here. Given the correct digital output it will produce a good analog output.
The amplifier is where the problem lies. It has no voltage gain and needs at least 1.2V of signal from the DAC resistors before it even starts to pass current through the loudspeaker. Even then, the lower volume levels will be distorted because the amplifier can't run in class A mode.
The 'dirty' fix is to add a resistor from the base to collector of Q1 so it is forced to conduct some current all the time. That would fix the distortion but be very inefficient.
The simplest 'good' fix is to forget Q1 and Q2 altogether (they will NEVER work as a quality amplifier) and connect the junction of R14 and R15 through a capacitor (100nF will do) to a LM386 or similar amplifier. That gives you a lot more volume for a lot less current and,withing the limitations of the LM386, much higher quality sound.
hi,
i tired your advice as well, using resistor between the base and collector reduced the sound level but distortion i don't know, also tired LM386, the same output as using the transistor
i think the code is working, R-2R ladder should be working with 2.2k and 4.7kohm, there is distortion in the audio i think because clearly there is audio as can be heard from the last posted video but is distorted...
--- Updated ---
hi,
thanks all, its working now
idk but at first i had first used portC and got no result, then i later changed to portA, same thing was obtained, later after changing the code and using portA i still got distorsion and when i just changed the port from portA to back to port C, the audio is recognizable.