Slow Teensy 3.2 12-bit DAC?

Status
Not open for further replies.
I'm looking at the DAC output on my scope and it looks janky.

I'm using the audio library to run a sine wave at 5kHz:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

static int freq = 440;
static int dir = 0;

// GUItool: begin automatically generated code
AudioSynthWaveform       waveform1;      //xy=220,160
AudioOutputAnalog        dac1;           //xy=472,158
AudioConnection          patchCord1(waveform1, dac1);
// GUItool: end automatically generated code

void setup() {
  analogWriteResolution(12);
  
  AudioMemory(10);

  waveform1.frequency(5000);
  waveform1.amplitude(1.0);
  waveform1.begin(WAVEFORM_SINE);
}

void loop() {

}

... but the scope is only showing about 9 level transitions per cycle. Using the scope's cursor, I can see that the level is updating about once every 23 microseconds. According to the chip's datasheet, the code-to-code settling time should be no longer than 1 microsecond (I know this isn't code-to-code, but it's pretty close). What am I doing wrong? I thought the DAC should be able to handle "audio-range" outputs quite happily but I'm failing down in the couple-of-kHz range.

EDIT: I've just seen and tested the Hackaday article which runs the DAC at 100kHz using DMA, and it works a treat. Does the Audio library not use DMA?
 
I'm looking at the DAC output on my scope and it looks janky.

I'm using the audio library to run a sine wave at 5kHz:

... but the scope is only showing about 9 level transitions per cycle. Using the scope's cursor, I can see that the level is updating about once every 23 microseconds. According to the chip's datasheet, the code-to-code settling time should be no longer than 1 microsecond (I know this isn't code-to-code, but it's pretty close). What am I doing wrong? I thought the DAC should be able to handle "audio-range" outputs quite happily but I'm failing down in the couple-of-kHz range.

Yes, that's expected. The Audio library handles signals at 44100 samples/second (23µs). You
need a reconstruction filter (aka anti-aliasing filter) on the output of the DAC with a cutoff
frequency around 20kHz.

Alternatively you'd need an output driver that does over-sampling at some multiple of 44.1kHz.

Standard audio DACs with I2S interfaces do this all internally (the oversampling), requiring
mininal external filtering.
 
I'm thinking of using a MAX292 as a DAC post-filter, but it has some requirements that I'm not sure I can satisfy around clocking frequency:
From the datasheet:

DAC Post-Filtering
When using the MAX291/MAX292/MAX295/MAX296 for
DAC post-filtering, synchronize the DAC and the filter
clocks. If clocks are not synchronized, beat frequencies will alias into the desired passband. The DAC’s
clock should be generated by dividing down the
switched-capacitor filter’s clock.


I suppose the generation of this clock and subsequent supply to the Teensy might be difficult, or just not worthwhile? I want to stay away from I2S for my own experimentation purposes.
 
What maximum signal frequency are you interested in? A simple passive filter might be enough depending on where the signal
goes (for instance human hearing acts as a low pass filter!).
 
Status
Not open for further replies.
Back
Top