DAC Output

Hi,

I am wondering if any of the Teensy models have a DAC for DC voltage output?

Thanks
Paul

The following models have one DAC output for voltages between 0 and 3.3v. Note, the DAC is different pin number on each processor. This DAC is one of the through hole pins on the back of the Teensy (next to pin 13):
  • Teensy LC (A12);
  • Teensy 3.2 (A14); (and)
  • Teensy 3.1 (A14) -- note, the Teensy 3.1 has been replaced with the 3.2 using the same pinout

The following Teensies have two DACs. Both DACs are on the outer rows of pins:
  • Teensy 3.5 (DAC0 is A21, DAC1 is A22); (and)
  • Teensy 3.6 (DAC0 is A21, DAC1 is A22).

The following Teensies do not have a DAC:
  • Teensy 2.x systems;
  • Teensy 3.0 (obsolete);
  • Teensy 4.0; (and)
  • Teensy 4.1.

Generally for the Teensy 4.0/4.1, if you want to play sounds, you want to use the I2S, I2S1, or S/PDIF systems to play sounds. There is support for using pins 10 and 12 for 'MQS' sounds, that acts sort of like a DAC. Note, if you use MQS, you cannot use the main SPI bus, since pin 12 is the SPI MOSI pin, and pin 10 is the default CS pin.

If you are playing sounds on the Teensy 3.2, you can use the Teensy prop shield (either the LC prop shield or the prop shield with motion sensors), which includes an amplifier connected to the DAC pin that you can hook up to a simple speaker. You use pin 5 to enable/disable the amplifier. You can use the prop shields on the Teensy 3.5/3.6, but you have to run a wire from A21 to the pin on the prop shield that supports the DAC. The Teensy LC can play limited sounds, but unfortunately the audio library doesn't support the Teensy LC (the LC doesn't have some instructions used by the library).

Here is a simple code modified from the examples to show how to use the DAC for audio, using the ToneSweep function:
Code:
/*
  Demo of the audio sweep function.
  The user specifies the amplitude,
  start and end frequencies (which can sweep up or down)
  and the length of time of the sweep.

  Modified to use the single DAC on the Teensy 3.1/3.2 and the first DAC on the
  Teensy 3.5 or 3.6.  The 3.0, 4.0 and 4.1 Teensies do not have a DAC.

  Pins:		Teensy LC	Teensy 3.2	Teensy 3.5/3.6

  DAC:		A12		A14		A21
  */

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// Define USE_PROPSHIELD if the Teensy uses the prop shield, and we want to
// enable the onboard amplifier.  Assume the LC/3.2 will have the propshield,
// but the 3.5/3.6 won't.

#if defined(__MKL26Z64__) || defined(__MK20DX256__)
#define USE_PROPSHIELD		1
#endif

// GUItool: begin automatically generated code (edited by meissner afterwards).
AudioSynthToneSweep	tonesweep;		//xy=102,174
AudioAmplifier		amp;			//xy=324,172
AudioOutputAnalog	dac;			//xy=452,189

AudioConnection		patchCord1 (tonesweep, amp);
AudioConnection		patchCord2 (amp,       0,   dac, 0);
// GUItool: end automatically generated code

const float		t_ampx	= 0.8;
const int		t_lox	= 10;
const int		t_hix	= 22000;
const float		t_timex	= 10;		// Length of time for the sweep in seconds

void setup(void)
{
  // Wait for at least 3 seconds for the USB serial connection
  Serial.begin (9600);
  while (!Serial && millis () < 3000)
    ;

  AudioMemory (8);
  amp.gain (0.5f);

  // Enable the prop shield speaker
#if USE_PROPSHIELD
  pinMode (5, OUTPUT);
  digitalWrite (5, HIGH);
#endif

  Serial.println("setup done");

  if (!tonesweep.play (t_ampx, t_lox, t_hix, t_timex)) {
    Serial.println ("ToneSweep - play failed");
    while (1)
      ;
  }

  // wait for the sweep to end
  Serial.println ("Tonesweep up started");
  while (tonesweep.isPlaying ())
    ;

  // and now reverse the sweep
  Serial.println ("Tonesweep down started");
  if (!tonesweep.play (t_ampx, t_hix, t_lox, t_timex)) {
    Serial.println("ToneSweep - play failed");
    while (1)
      ;
  }

  // wait for the sweep to end
  while (tonesweep.isPlaying ())
    ;
  Serial.println("Done");
}

void loop(void)
{
}
 
Hi,

Thank you for such a detailed reply. I will investigate which option is most suited to my project.

Cheers
Paul
 
If you have a 4.0/4.1, couldn't you use a PWM pin for that? Would it be much different from using a DAC in terms of quality?
 
If you have a 4.0/4.1, couldn't you use a PWM pin for that? Would it be much different from using a DAC in terms of quality?

Quality will be measurably different as the DAC does a true voltage 0 to 3.3V out, not a modulated set of PIN frequency controlled ON/OFF cycles to 'over time' "give" the 'desired' voltage.

It does work as that is how the Talkie library works on DAC or PWM when no DAC - but the DAC gives better sound even with that library.
 
Aside from issue of filtering away the carrier frequency, all low pass filtered PWM signal suffer from poor power supply noise rejection. So do real DACs if their reference voltage is the power supply, but usually if you care about this you would configure the DAC to use a stable reference voltage.

Without a stable reference voltage, any noise present on the power supply couples directly into the output signal. Or at least the portion of the PWM duty cycle of it does, so at 50% output you get the power supply's noise attenuated by only a factor of 2 (or 6 dB signal).

If this is a major concern, you could improve the PWM situation by creating a "clean" power supply to run just a buffer chip. Maybe that makes sense in some situations. But if you're just building a project (rather than designing a product for volume production) and you're going to add any hardware, you might as well add a real DAC rather than a buffer chip. Then again, for PWM you need to add a filter, and if you want to greatly attenuate the carrier and still have significant signal bandwidth, you probably need a pretty involved filter that's as much cost and more work than a DAC chip. A single R-C filter only works if you can live with some of the carrier still present or you can accept very low bandwitdth output.
 
Back
Top