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

Thread: DAC Filtering on Teensy 3.2

  1. #1

    DAC Filtering on Teensy 3.2

    Hi all,

    I am very new to Teensy and have set up a simple code to run a single 900 Hz tone to the DAC and into an oscilloscope to figure out the resistor I need to put on my low pass filter to get a nice crisp and clean sine wave. Unfortunately, the signal I seem to be getting doesn't even look like a sine wave.Click image for larger version. 

Name:	42709133_553532918431947_7210327213181239296_n.jpg 
Views:	46 
Size:	106.9 KB 
ID:	14855 Am I supposed to setup the DAC before I use it or does the DAC work when it is called from pin A14. My code is below and any help would be much appreciated! Sorry if this is a simple, stupid question.
    The closest I was able to get to a sine wave(pretty noisy):
    Click image for larger version. 

Name:	42697454_168641370716909_964549427324780544_n.jpg 
Views:	37 
Size:	95.0 KB 
ID:	14853
    Click image for larger version. 

Name:	42692986_232128950989372_3025748810140745728_n.jpg 
Views:	41 
Size:	92.8 KB 
ID:	14854

    void setup() {
      pinMode(12, OUTPUT);
      digitalWrite(12, HIGH);
      //pinMode(3, OUTPUT);
      tone(A14, 900, 500000000000);
    void loop() {
    Thanks in advance!

  2. #2
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Hi LunarEclipse57,

    The function tone() outputs a square wave, not a sine wave, see this page: [scroll down to the bottom of the page].

    For a sine wave output you need to use PJRC's "Audio System Design Tool", here:

    Design your circuit and Export the code:

    Click image for larger version. 

Name:	Screenshot.png 
Views:	36 
Size:	113.9 KB 
ID:	14857

    In void setup(), set the frequency & amplitude and define AudioMemory buffers.

    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    // GUItool: begin automatically generated code
    AudioSynthWaveformSine   sine1;          //xy=316,337
    AudioOutputAnalog        dac1;           //xy=484,336
    AudioConnection          patchCord1(sine1, dac1);
    // GUItool: end automatically generated code
    void setup()
    void loop()
    Compile and upload to your Teensy.

    On the oscilloscope:

    Click image for larger version. 

Name:	900Hz sine.jpg 
Views:	31 
Size:	75.7 KB 
ID:	14858


  3. #3
    Thank you, it was silly of me to just assume that the tone librabry outputs a sine wave.

Posting Permissions

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