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

Thread: Teensy 3.5 - How to write data to DAC pins easily?

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    16

    Teensy 3.5 - How to write data to DAC pins easily?

    Hi all,

    I want to just output some values to the DAC pins in my loop() code.

    Cannot seem to find information on how to do this.

    I don't want to use the audio library.

    Any help?

    Thanks!

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,421
    You might try using analogWrite()...
    https://www.arduino.cc/reference/en/...o/analogwrite/

  3. #3
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    2,626
    Quote Originally Posted by mike6789 View Post
    Hi all,

    I want to just output some values to the DAC pins in my loop() code.

    Cannot seem to find information on how to do this.

    I don't want to use the audio library.

    Any help?

    Thanks!
    You use the analogWrite function. If you are writing to a DAC pin (A21/A22 on the Teensy 3.5/3.6, A14 on the Teensy 3.1/3.2, or A12 on the Teensy LC), it does a real analog write (i.e. adjusts the voltage of the pin). You might need an amplifier on the pin(s) before connecting it to a speaker.

    Due to poor naming of the function from original Arduino systems, analogWrite on a digital pin that supports PWM, rapidly turns the pin on/off, so that it approximates an analog signal (if you are looking at a LED, it will appear to dim the LED, as the light turns on/off faster than the eye can see). Typically you would need a low pass filter if you want a PWM output to better approximate an analog signal.

    And yes, IMHO, the original Arduino should have called the second function something like pwmWrite, but they didn't.

  4. #4
    Junior Member
    Join Date
    Jul 2014
    Posts
    16
    Quote Originally Posted by MichaelMeissner View Post
    You use the analogWrite function. If you are writing to a DAC pin (A21/A22 on the Teensy 3.5/3.6, A14 on the Teensy 3.1/3.2, or A12 on the Teensy LC), it does a real analog write (i.e. adjusts the voltage of the pin). You might need an amplifier on the pin(s) before connecting it to a speaker.

    Due to poor naming of the function from original Arduino systems, analogWrite on a digital pin that supports PWM, rapidly turns the pin on/off, so that it approximates an analog signal (if you are looking at a LED, it will appear to dim the LED, as the light turns on/off faster than the eye can see). Typically you would need a low pass filter if you want a PWM output to better approximate an analog signal.

    And yes, IMHO, the original Arduino should have called the second function something like pwmWrite, but they didn't.
    Oops... duh... thanks guys!

Posting Permissions

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