Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: very basic questions re: DAC on teensy

  1. #1
    Junior Member
    Join Date
    Oct 2022
    Posts
    5

    very basic questions re: DAC on teensy

    Hi! I'm absolutely new to the world of arduino/teensy/etc., so forgive my ignorance -- I have yet to read any tutorials, etc. I'm just trying to select the right board for my project.

    I understand that the Teensy boards all have DACs on them, correct?

    Assuming that's correct, is the analog output roughly equivalent to "line level"? Meaning, going into the impedance of the average "line in" it's going to work OK?

    Is the DAC output just a couple of pins somewhere on the board that can be soldered to? (Meaning, no other module is required I assume?)

    I'm going to be reading a hall effect sensor, a button or two, and some kind of rotary knob (i.e. with detentes that signals as each detente is reached), generating a sine wave out of the DAC, and flashing a couple LEDs. (I assume the teensy is capable of much more than this, but just wanted to explain the basics.)

    Thanks!

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    4,370

    Cool

    Quote Originally Posted by pqov View Post
    Hi! I'm absolutely new to the world of arduino/teensy/etc., so forgive my ignorance -- I have yet to read any tutorials, etc. I'm just trying to select the right board for my project.

    I understand that the Teensy boards all have DACs on them, correct?
    I'm a software guy, so I will defer information about details and such to others.

    First of all, there is are older variants of Teensy (Teensy 2.0 and 2.0++) that really aren't part of the modern Teensies normally talked about here. These teensies use the 8-bit AVR 32u4 chips, and not the ARM based chips the more modern Teensies use. I don't think the AVR 32u4 has DAC support at all.

    In addition, two of the 'modern' Teensies (3.0 and 3.1) have been obsoleted for several years now. IIRC, the 3.0 did not have a DAC. The 3.1 was replaced by the 3.2 (there are some minor differences, but the 3.1 and 3.2 are essentially the same). Of the Teensies:
    • Teensy LC: Has a single DAC;
    • Teensy 3.1/3.2: Has a single DAC;
    • Teensy 3.5/3.6: Has two DACs so you could do stereo;
    • Teensy 4.0/4.1: Does not have DAC's (the chip maker removed the DAC capability).


    Unfortunately, with the current chip shortages, the Teensy LC, 3.2, 3.5, and 3.6 are unobtainable. I think Paul said that maybe there was a batch of LC's that was in production. I don't remember if it will be available shortly, or if it went out, and it has been sold out.

    I believe the Teensy 4.0 has been out of stock, but the PJRC product page says they will have some availability in December. At the moment, Teensy 4.1s are available (though mostly without the ethernet support that part of the initial design, but you likely don't need that).

    The Teensy 4.0/4.1 has support for MQSR/MQSL, which is a 'medium quality' system for playing sounds. You can use this like a DAC. The trouble with MQSR/MQSL is it uses hardwired pins. One of these pins (12) is one that is needed to do SPI for hooking up faster displays. There are alternate ways to do displays, but it can be a problem.

    Normally however, you use the audio adapter (https://www.pjrc.com/store/teensy3_audio.html) or low cost PT8211 board (https://www.pjrc.com/store/pt8211_kit.html). The audio adapter has both 3.5mm headphone and line level output. The PT8211 only does line level. You can also buy external I2S devices to emit sounds that you hook up to the appropriate pins.

    For line level output, you normally have to hook up an amplifier before you attach a speaker. The DACs just change the voltage from 0 to an upper limit (normally 3.3v), that you would have to attach a speaker. Adafruit sells a nice combined mono speaker that takes 3 pins (ground, DAC/line out output, and power, https://www.adafruit.com/product/3885).

    Quote Originally Posted by pqov View Post
    Assuming that's correct, is the analog output roughly equivalent to "line level"? Meaning, going into the impedance of the average "line in" it's going to work OK?
    Here is where somebody else needs to chime in.

    Quote Originally Posted by pqov View Post
    Is the DAC output just a couple of pins somewhere on the board that can be soldered to? (Meaning, no other module is required I assume?)
    On the Teensys with DACs yes. The DAC is just a pin that you vary the voltage to. The interface is to call analogWrite on the pin to vary the voltage. Additionally, there are PWM (pulse width modulation) pins where you can tell the Teensy to rapidly turn the pin on/off, and if you hook up an amp and speaker, you can hear sounds. Unfortunately the initial Arduino code uses analogWrite to also control PWM pins (the original AVRs did not have DACs). So if the physical pin is a DAC, you get true analog output, if it is a PWM pin, you get this rapid on/off to simulate a DAC.

    Quote Originally Posted by pqov View Post
    I'm going to be reading a hall effect sensor, a button or two, and some kind of rotary knob (i.e. with detentes that signals as each detente is reached), generating a sine wave out of the DAC, and flashing a couple LEDs. (I assume the teensy is capable of much more than this, but just wanted to explain the basics.)

    Thanks!
    For this purpose, you likely can use any PWM pin. If you want to play music, you probably want to step up from PWM. Using DACs is good enough for things like props where you want to play recorded sounds, but if you want true audio level music, you need to step up to the audio adapter.

  3. #3
    Junior Member
    Join Date
    Oct 2022
    Posts
    5
    Thanks for the detailed reply!

    Sad to hear that the DAC is gone in the latest versions... I guess the Arduino has an analogous audio board as well (?) but part of the design objective here is to minimize the assembly/connectivity complexity, so I was hoping for something with a built-in DAC, and the internet pointed me to the Teensy.

    At any rate, I'll keep checking out my options. Much obliged!

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,366
    With Teensy 4.0 and 4.1, you might try the MQS output. It's 353 kHz PWM with noise shaping tricks which you low-pass filter with a resistor and capacitor. Sound quality is pretty good.

  5. #5
    Junior Member
    Join Date
    Oct 2022
    Posts
    5
    Thanks Paul -- basically the same idea as a class D audio amp + speaker, right?

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,366
    Yes, more or less. There is some noise shaping stuff it's doing in varying the pulse widths, which maybe some class D amps do too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •