DAC on Audio System Design Tool not working

Status
Not open for further replies.

joaotragtenberg

Active member
Hello, I am trying to use the DAC output on the teensy 3.2 and did not have success using it with the Audio System Design Tool.
It worked well with the analogWrite() method. I ran the "Simple DAC sine wave test code" I got from the https://www.pjrc.com/teensy/teensy31.html page.

I tried to make a simple DC1 blink to check with my multimeter (I can only use a multimeter in college) if the DAC is working but it wasn't.
I simply put one multimeter probe on the DAC/14 pin and another on GND and ran this code:


#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveformDc dc1; //xy=232,402
AudioOutputAnalog dac1; //xy=538,240
AudioConnection patchCord1(dc1, dac1);
// GUItool: end automatically generated code


void setup() {
pinMode(13, OUTPUT);
dac1.analogReference(EXTERNAL);
}

void loop() {
dc1.amplitude(1.0);
digitalWrite(13, HIGH); //I put the LED to blink just to make sure when the DAC voltage should go HIGH
delay(1000);
dc1.amplitude(-1.0);
digitalWrite(13, LOW);
delay(1000);
}


can anyone help me?
 
Last edited:
Hello Paul! I am new on tennsy platform and i am interested in particular about audio development. Can you tell me if i can use audio system tool without Audio shield needed. For instance i want to output a sine wave whit variable frequency and modulated to play. Is this thing possible without any shield to output directly to A14-DAC, if yes, how? Thanks in advance!
 
vincentiuș;127239 said:
Hello Paul! I am new on tennsy platform and i am interested in particular about audio development. Can you tell me if i can use audio system tool without Audio shield needed. For instance i want to output a sine wave whit variable frequency and modulated to play. Is this thing possible without any shield to output directly to A14-DAC, if yes, how? Thanks in advance!

Yes.
Use the Audio Library Design Tool: http://www.pjrc.com/teensy/td_libs_Audio.html
You need a Teensy >= 3.0 (not Teensy-LC)
 
Yes.
Use the Audio Library Design Tool: http://www.pjrc.com/teensy/td_libs_Audio.html
You need a Teensy >= 3.0 (not Teensy-LC)

Actually you do not want either the 3.0 or the LC. The Teensy-3.0 did NOT have a DAC. The Audio library does not support the Teensy-LC, since some functions uses instructions that are not present in the Teensy-LC. Given the 3.0 is out of stock and not likely to come back, it probably is only an issue for us dinosaurs that have been using Teensy since the original kickstarter campaign. I think I have something like 4 Teensy 3.0's kicking around/ Fortunately, the original black PCB makes it easy to distinguish from the newer Teensies.

However, you can write your own code to access the DAC on the Teensy-LC.

Note, the DAC is not amplified. The simplest method to amplify the DAC on the 3.1/3.2 is to use one of the prop shields (either the full prop shield with motion sensors or the LC prop shield without the sensors). If you are using the prop shield for audio, you need to turn pin 5 on to enable the amplifier. You could use other amplifiers, such as the mono amplifier Adafruit sells. If you use the Teensy 3.5 or 3.6, you will need to connect a wire from the 3.1/3.2 location of the DAC on the prop shield to 3 pins down from pin 13 where DAC0 is located on the Teensy 3.5/3.6. The Teensy 3.5/3.6 has two DACs, so you could play stereo with them instead of just mono.

 
Last edited:
to be clear, I am using Tennsy 3.2 whitout shield, the output of the DAC it will be amplified by a TL chip + more, leaving that aside. The issue is with the output, because i don't find the instructions or controls that make the output thru A14-DAC pin insted sgtl5000_1 and other controls. The question is if I can enjoy the Audio System design tool whitout any shield, if yes, what are the intructions to output directly via A14-DAC?

for instance i generated this:

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveformSine sine1; //xy=123,92
AudioSynthWaveformSineModulated sine_fm1; //xy=250,38
AudioMixer4 mixer1; //xy=377,83
AudioOutputAnalog dac1; //xy=508,39
AudioConnection patchCord1(sine1, sine_fm1);
AudioConnection patchCord2(sine_fm1, 0, mixer1, 0);
AudioConnection patchCord3(mixer1, dac1);
// GUItool: end automatically generated code

void setup() {

}

void loop() {

}


Whitout the pots configurations, what are the instruction to complet the code, to output this thru pin A14-DAC?
 
At the very least, you need AudioMemory() and some calls to configure the frequency and amplitude of those waveforms.

Look at File > Examples > Audio > Tutorial > Part_2_08_Oscillators for ideas. Or look at the info in the design tool about the functions each object provides.
 
This is a rather simple test that I used to test the amplification with the prop shield. Outside of the prop shield, you can delete these two lines:
Code:
  pinMode(5, OUTPUT);
  digitalWrite(5, 1);		// Enable Amplified

Here is the code:

Code:
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <Audio.h>
#include <SerialFlash.h>

// from: https://forum.pjrc.com/threads/33328-Prop-Shield-Beta-Test?p=99236&viewfull=1#post99236
// modified by Michael Meissner

// GUItool: begin automatically generated code
AudioSynthWaveformSine   sine1;          //xy=180,469
AudioOutputAnalog        dac1;           //xy=380,468
AudioConnection          patchCord1(sine1, dac1);
// GUItool: end automatically generated code

int freq = 1000;

void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;
  Serial.println("Setting up");
  pinMode(5, OUTPUT);
  digitalWrite(5, 1);		// Enable Amplified.
  AudioMemory(12);
  sine1.amplitude(1.0);
  sine1.frequency(freq);
  Serial.println("Send + to increase freq, - to decrease freq, a to turn off amp, A to turn on amp, or num for freq.");
}

void loop()
{
  if (Serial.available()) {
    int ch = Serial.read();
    switch (ch)
      {
      case '+':
	freq += 100;
	sine1.frequency(freq);
	Serial.print ("New frequency ");
	Serial.println (freq);
	break;

      case '-':
	freq -= 100;
	sine1.frequency(freq);
	Serial.print ("New frequency ");
	Serial.println (freq);
	break;

      case 'a':
	digitalWrite (5, 0);
	Serial.println ("Amp off");
	break;

      case 'A':
	digitalWrite (5, 1);
	Serial.println ("Amp on");
	break;

      case '0':
      case '1':
      case '2':
      case '3':
      case '4':
      case '5':
      case '6':
      case '7':
      case '8':
      case '9':
	{
	  bool looping = true;
	  freq = ch - '0';
	  do
	    {
	      if (Serial.available ())
		{
		  ch = Serial.read ();
		  if (ch >= '0' && ch <= '9')
		    freq = (freq * 10) + (ch - '0');
		  else
		    looping = false;
		}
	    }
	  while (looping);
	}

	Serial.print ("New frequency ");
	Serial.println (freq);
	sine1.frequency(freq);
	break;

      case ' ':
      case '\n':
      case '\t':
      case '\r':
	break;

      default:
	Serial.print ("Unknown character '");
	Serial.print ((char) ch);
	Serial.println ("'");
      }
  }
}
 
Last edited:
Here is the sketch that i made and I am trying to output at the same time both signals, onboard Dac and MCP49xx dac. The problem is that i don't find which name of the tabVal from the library should be in parentheses here dac.output( ? ); //??
here is the strech:

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <DAC_MCP49xx.h>
#define SS_PIN 6
#define LDAC_PIN 7
// GUItool: begin automatically generated code

AudioSynthWaveform waveform1; //xy=110,75
AudioOutputAnalog audioOutput; //xy=303,78
AudioConnection patchCord1(waveform1, 0, audioOutput, 0);
AudioConnection patchCord2(waveform1, 0, audioOutput, 1);
// GUItool: end automatically generated code

DAC_MCP49xx dac(DAC_MCP49xx::MCP4921, SS_PIN);

void setup() {
dac.setSPIDivider(SPI_CLOCK_DIV2);
AudioMemory(16);
waveform1.begin(WAVEFORM_SQUARE);
waveform1.amplitude(0.99);
}

void loop() {
float freq = map(analogRead(A0), 0, 4095, 0.1, 2000);
waveform1.frequency(freq);
dac.output( ? ); //??

}
 
This code will send your audio signal to the A14/DAC pin on Teensy 3.2.

The audio library does not have any code to use Microchip MCP4921 DAC chips. You can use that library to write data to such a chip, but it won't happen automatically from the audio library.
 
Status
Not open for further replies.
Back
Top