Connecting a Speaker to Teensy 3.1 DAC / A14 ?

Status
Not open for further replies.

SDL1000

New member
Hi
Any experience with connection a speaker to Teensy 3.1 DAC / A14 ?
I would like a complete datasheet of the Teensy 3.1 !

What load is possible on the A14/DAC output ( voltage, max current and impedance ) ?


Thanks in advance
 
I found this info in the manual for the K20 Sub-Family Data Sheet, Rev. 3, 11/2012 posted at pjrc.com in the teensy 3.1 reference section. Looks like the DAC will need a buffer to run a speaker.

6.6.3 12-bit DAC electrical characteristics
6.6.3.1 12-bit DAC operating requirements
Table 29. 12-bit DAC operating requirements
Symbol Desciption Min. Max. Unit Notes
VDDA Supply voltage 1.71 3.6 V
VDACR Reference voltage 1.13 3.6 V 1
TA Temperature Operating temperature
range of the device
°C
CL Output load capacitance — 100 pF 2
IL Output load current — 1 mA
1. The DAC reference can be selected to be VDDA or the voltage output of the VREF module (VREF_OUT)
2. A small load capacitance (47 pF) can improve the bandwidth performance of the DAC
 
The Teensy Datasheet is available for download on the pjrc website.

It should be obvious that the DAC output can not drive a low impedance speaker directly, for several reasons:
a) The DAC is unipolar, thus there is always an offset of Vref/2 which would flow through the speaker, causing thermal loss and distortion.
b) Behind a DAC, there must always be a low pass filter (3dB frequency <= fs/2, slope >= 12dB/oct) first which eliminates the sampling frequency edges and spikes because they can cause distortion and RF interference, and thus destroy speakers and/or headphones and your dog's ears ;-)
c) The maximum output current of the DAC is 1mA. At 3.3V, that means that the minimal load impedance is 3.3kOhm.

But for very first and quick tests and diagnosing, you may connect a old-fashioned crystal ear-plug to the DAC output.
 
I've run the DAC output pin directly into amplified computer speakers, with usually good results. Most of them have a DC blocking capacitor at their input... but be aware you could damage speakers that lack DC blocking if the amp inside happily amplifies the DC offset. It's safest to connect a 10 uF capacitor in series, with the + side to the Teensy DAC pin and - side to the signal input. Of course, you also need to connect the grounds directly.

Proper filtering would of course be better. But for quick testing, amplified computer speakers work pretty well.
 
Hi,

It is interesting that I asked more or less the same question on a different thread. I can say for sure you can not drive the speaker directly from this pin especially using the RC circuit mentioned on PJRC for other pins... I also talked about it up on Trossen forum (http://forums.trossenrobotics.com/showthread.php?6632-PhantomX-using-a-Teensy-3-1&p=67603#post67603)

I am thinking of trying to breadboard it up with small amplifier. May start with LM386 as Radioshack carries them (don't have to wait for order to digikey or mouser). Will probably start with minimal hardware hookup as mentioned in datasheet. Two caps and a resistor. May either use 10k pot or another suggested two 4.7k resistors as a divider... Will see how this works in the next couple of days.
 
Hi,

It is interesting that I asked more or less the same question on a different thread(https://forum.pjrc.com/threads/27949-Sound-on-my-Teensy-3-x-Carrier-boards). I can say for sure you can not drive the speaker directly from this pin especially using the RC circuit mentioned on PJRC for other pins... I also talked about it up on Trossen forum (http://forums.trossenrobotics.com/showthread.php?6632-PhantomX-using-a-Teensy-3-1&p=67603#post67603)

I am thinking of trying to breadboard it up with small amplifier. May start with LM386 as Radioshack carries them (don't have to wait for order to digikey or mouser). Will probably start with minimal hardware hookup as mentioned in datasheet. Two caps and a resistor. May either use 10k pot or another suggested two 4.7k resistors as a divider... Will see how this works in the next couple of days.
 
Sorry if this is obvious stuff, but my electronics class was a long time ago...

So I have tried breadboard of hookup up an LM386 (http://www.ti.com/lit/ds/symlink/lm386.pdf) up to Teensy 3.1 DAC. I am trying some of the simple example hookups (page 6 in datasheet), like the minimal hookup also added 10k Cap to increase gain and I am not getting any sound. Note: I replaced the 10k trim pot for hooking up DAC with two 4.6k resistors...

I am experimenting using SamplePlayer example of audio library. I am using a jumper wire to toggle one or more IO pins to ground, to simulate the buttons.

When I look the DAC pin with my Logic Analyzer, with the Analog readings, it looks like with no sound, the pin is outputting about .5v. I thought I read somewhere that it should be about 1.6v? To make sure my circuit was not messing with it, I unwrapped a new T3.1, downloaded program to it, and again measured about .56v with no sound selected.

Here is a screenshot from LA showing two sounds being selected...
LA T3.1 DAC sound.jpg

The range of voltage for the sounds was maybe .3x to .7x...

Suggestions? Punt? Should the DAC hook up differently to LM386 through maybe different stuff to both + and -?

Thanks
Kurt
 
It looks like the lm386 wants a ground referenced input. This means that it expects the input to vary around ground.

The teensy DAC has outputs that vary around a fixed DC voltage that depends on the voltage reference used. In this case, it looks like the DAC is set up to use the 1.2v reference, so the DC output level (no sound playing) is around 0.6 volts.

The problem that you're seeing is that the lm386 is amplifying the difference between the positive and negative terminals by 200. The one terminal is fixed to ground, and the other varies around ~0.6v, so the lm386 will try to drive the output to 200*0.6 or 120 volts.

What you need to do is add a coupling capacitor in series with the DAC output to remove the DC component. This would look like a ~10uF electrolytic cap with the + terminal connected directly to the DAC output and the - terminal connected to the input of the voltage divider. This will force the input of the lm386 to vary around 0v.

I would also suggest leaving the lm386 set to a gain of twenty at first. The maximum peak to peak output amplitude of the LM 386 is roughly equal to its supply voltage. If you're using a gain of twenty and a five volt supply, the maximum input signal for the maximum output signal is 5/20=0.25 volts peak to peak. That's already less than the max DAC output level, so there isn't any need for more gain.
 
whollender is right. The DC component of the DAC output needs to be removed before feeding the signal into the LM386. If not, this will drive the LM386 into saturation which, in the best case, will give no audible output signal, and in the worst case kill the LM386. The default amplification factor of the LM386 is large enough without additional components to increase gain.
 
Thanks guys,

I removed the 10K cap from the gain side (pins 1,8), used it between the output of the DAC and the input to voltage dividers. The good news is I am now getting sound (noise) when I press the button (decided to put button on breadboard instead of manually shorting to ground...).

So far it sounds a lot more like noise than sounds like tom/tom or Snair... Could be partially the cheap speaker from radioshack... Could be because they did not have 250ohm cap but only 220...

Again for case maybe I should punt... But will still experiment some...
 
The DAC output may still be overdriving the LM 386. Try lowering the DAC volume (I think there is that capability in the audio lib)
 
Thanks, I will take a look.

I know there is a call to set the shield volume in the sketch: audioShield.volume(0.5);

One thing that threw me earlier was I was expecting a signal that was centered around 1.6v or the like, as the sketch has:
Code:
  // by default the Teensy 3.1 DAC uses 3.3Vp-p output
  // if your 3.3V power has noise, switching to the
  // internal 1.2V reference can give you a clean signal
  //dac.analogReference(INTERNAL);
But I think by default it is using INTERNAL (more or less). I think this is because: in output_dac.cpp, the begin function starts off with:
Code:
	SIM_SCGC2 |= SIM_SCGC2_DAC0;
	DAC0_C0 = DAC_C0_DACEN;                   // 1.2V VDDA is DACREF_2
	// slowly ramp up to DC voltage, approx 1/4 second
	for (int16_t i=0; i<2048; i+=8) {
		*(int16_t *)&(DAC0_DAT0L) = i;
		delay(1);
	}
And looking at the analogReference member
Code:
void AudioOutputAnalog::analogReference(int ref)
{
	// TODO: this should ramp gradually to the new DC level
	if (ref == INTERNAL) {
		DAC0_C0 &= ~DAC_C0_DACRFS; // 1.2V
	} else {
		DAC0_C0 |= DAC_C0_DACRFS;  // 3.3V
	}
}
It appears like to use the external reference, the C0 register would need DAC_C0_DACRFS defined, which the init would have removed. Not sure if this is now by design, but if so, maybe example program should be updated...

Well now to get back to playing
 
I have done some more playing... I don't think there is a setVolume on the DAC class...

But still wonder some about the hookup to the LM386. That is with the Capacitor hooked up between the DAC output and the voltage divider, it did move the zero point of the voltage going into the divider to 0 as mentioned. I hooked up the LA again, and this time again hooked up a lead to the beginning of divider, I also hooked up a second lead to the + input to the speaker, to see what it is seeing. and if I am reading this right it is only getting the positive side of the wave? again I am really green and rusty on Analog stuff...
LA T3.1 DAC sound.jpg
 
Rather than guessing at method names, its best to look at the documentation. The method you want is lineOutLevel(both);
http://www.pjrc.com/teensy/gui/?info=AudioControlSGTL5000

The range of adjustment is 1.1V to 3.3V. This is for setting the line out level, not a volume control. The default (which was changed during beta development of the audio library) is indeed INTERNAL, and that old example needs to be updated.
 
Nantonos, wouldn't the line out level method only change the output level if the audio board was being used? It doesn't seem logical for it to change the DAC output level.

KurtE, in the last screenshot, it looks like you have either digital pulses going into the cap and divider, or the DAC is getting enabled and disabled a bunch. This is causing the output of the cap to have an exponential decay type of response.

Earlier you posted a screenshot of a more normal audio signal that varied around a fixed voltage. What changed?

With the cap in place, the voltage at the divider input should look just like the earlier screenshot, but varying around zero instead of having a positive offset.
 
Thanks guys,

Note: in the later screen shot you see two analog signals. The bottom one is the one going into the divider, which does now vary around a zero point which is more or less zero. with highs around .2 and lows around maybe -.22 in some of the measurements I showed. The other channel shown is what is being fed into the + terminal of the speaker.

Here is a more zoomed in look of the two...

LA T3.1 DAC sound.jpg
 
Hmm, it still looks like the lm386 output is clipping. I would try replacing the ground side of your resistor divider with a 1k resistor to see if that helps. That should reduce the gain through the divider enough to see if you can get a clean signal out to the speaker.

Once you get the gain dialed in, the voltage you measure at the speaker terminal should look pretty much identical to the input of the resistor divider with a little higher amplitude.

Edit: I just found the analog input range for the Saleae logic analyzers, and they mention 0v as the lower limit so the reason you're only seeing the positive side of the output may be because of the logic analyzer itself. Try measuring directly at the output of the lm386 because it will have a fixed DC offset of ~2.5v (assuming a five volt supply) and the voltage there can't go below ground (or above the supply voltage).
 
Last edited:
Thanks,

Yep, the analog did not want to show below zero. So changing the probe point helped to see. Also changed to 1K as you mentioned.

Signal is looking better on negative side. Maybe sound output may also be off as RadioShack did not have all of the precise caps they mentioned.

Like instead of 250 I have 220, and for other one that mentioned .05 they only had .1
LA T3.1 DAC sound.jpg

Will check around and see if I have some others stashed away from other projects...
Note: this is with the 1K resistor
 
I wouldn't worry about the 220uF capacitor change too much, but the 0.1uF cap may be causing an issue with stability.

If you have multiple 0.1uF caps, try putting another one in series with the ten ohm resistor and 0.1uF cap that's already there. Caps in series will combine like resistors in parallel so this will give you the correct 0.05uF capacitance at the lm386 output.

If you have a third 0.1uF cap, I would suggest putting it directly between the voltage supply pin (pin 6) and the ground pin (pin 4). This is called power supply decoupling, and will help with noise and stability by providing a short current path for transient currents on the supply lines. You can also think of it as a charge buffer on the voltage supply that can supply short term current to the ic.

Good luck! You're getting really close.
 
Again thanks,

I was wondering about having decoupling capacitor... The spec sheet did not show one, but I have a tendency to put one in for each IC on GP.

I did as you suggested and put one in for that as well as put two in series to make up the .05 (thanks I forgot about that from my old circuit analyzes class that I took a few decades ago...

The speaker is not generating a lot of sound yet, but I think I can fix some of this with changing back to larger resistor...

LA T3.1 DAC sound.jpg

As you can se the signal is looking a lot nicer now!

Thanks again.
 
I'd be a bit wary of going back to a larger resistor in the voltage divider. The voltage waveform in your last post shows a minimum of 1V and a maximum of 4V, which is pretty much as far as the LM386 can go using a 5V supply. If you do try a larger resistor, you'll probably end up overdriving the LM386 again.

If you need it to be louder, you have a few options. One is to simply use a higher voltage supply for the LM386, such as a 9V battery, so that you can use a higher resistor value in the divider without overdriving the LM386.

Another option would be to try another speaker. I've had good results at moderate volumes with sparkfun's 0.5W speaker, but I was using it together with their mono audio amp breakout instead of an LM386.
 
Actually I tried a different sound out of the test case (gong) and it sounded alright. I think it is probably good enough to try an update to my simple Teensy breakout board... I have it setup to probably use the 15mm speaker instead of the 12mm buzzer/speaker I have in current board.

Teensy-AX-board.jpg

Thanks again.
 
Again thanks,

I was wondering about having decoupling capacitor... The spec sheet did not show one, but I have a tendency to put one in for each IC on GP.

I did as you suggested and put one in for that as well as put two in series to make up the .05 (thanks I forgot about that from my old circuit analyzes class that I took a few decades ago...

The speaker is not generating a lot of sound yet, but I think I can fix some of this with changing back to larger resistor...

View attachment 4327

As you can se the signal is looking a lot nicer now!

Thanks again.
Hi Kurt

Are you still using this setup with the lm386 or did you made some changes afterwards?
Still happy with it?
 
Status
Not open for further replies.
Back
Top