DAC Filtering on Teensy 3.2

Status
Not open for further replies.

LunarEclipse57

New member
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. 42709133_553532918431947_7210327213181239296_n.jpg 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):
42697454_168641370716909_964549427324780544_n.jpg
Circuit:
42692986_232128950989372_3025748810140745728_n.jpg

Code:
void setup() {
  pinMode(12, OUTPUT);
  digitalWrite(12, HIGH);
  //pinMode(3, OUTPUT);
  tone(A14, 900, 500000000000);
  delayMicroseconds(3010000);

}

void loop() {
}

Thanks in advance!
 
Hi LunarEclipse57,

The function tone() outputs a square wave, not a sine wave, see this page: https://www.pjrc.com/teensy/td_pulse.html [scroll down to the bottom of the page].

For a sine wave output you need to use PJRC's "Audio System Design Tool", here: https://www.pjrc.com/teensy/gui/.

Design your circuit and Export the code:

Screenshot.png

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

Code:
#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()
{
  sine1.amplitude(1);
  sine1.frequency(900);
  AudioMemory(12);
}

void loop()
{
}

Compile and upload to your Teensy.

On the oscilloscope:

900Hz sine.jpg

Regards,
Paul
 
Status
Not open for further replies.
Back
Top